Pure Bash Bible

This page summarizes the projects mentioned and recommended in the original post on news.ycombinator.com

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
  • pure-sh-bible

    📖 A collection of pure POSIX sh alternatives to external processes.

  • Do you have any specific examples to cite? The snippets are meant to be run in POSIX-compliant shells like dash/yash/ash/etc, not just Bash in compatibility mode.

    In fact, there used to be a section which listed workarounds[1] for bugs in dash, but they have since been fixed[2]. If you are still using an old version of dash, you may need to use them.

    [1] https://github.com/dylanaraps/pure-sh-bible/commit/70f410ebb...

    [2] https://github.com/dylanaraps/pure-sh-bible/issues/13

  • pure-bash-bible

    📖 A collection of pure bash alternatives to external processes.

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
  • shunit2

    shUnit2 is a xUnit based unit test framework for Bourne based shell scripts.

  • > or something that would proper unit testing

    <https://github.com/kward/shunit2>

  • bish

    Bish is a language that compiles to Bash. It's designed to give shell scripting a more comfortable and modern feel.

  • I'd love to see a little language which compiles to _readable_ bash. Could it be so hard? There's a dead project that comes up now and then called bish.

    https://github.com/tdenniston/bish

  • testing-in-bash

    Bash test framework comparison

  • sh

    A shell parser, formatter, and interpreter with bash support; includes shfmt (by mvdan)

  • https://github.com/mvdan/sh

    And finally, checkbashisms if you intend on making pure posix scripts that are compatible with debian/ubuntu's dash. It is part of the debian's devscripts suite, but is often individually packaged in other distros.

    > Also you can use the chat as a learning tool

    Or you could learn from a guide written by people who have suffered decades of experience of the pitfalls of shell scripting and have shared their woes.

    https://mywiki.wooledge.org/BashGuide

  • ShellCheck

    ShellCheck, a static analysis tool for shell scripts

  • First, shellcheck:

    https://www.shellcheck.net/

    I systematically run this on my scripts before using them.

    Then shfmt for nice, reliable autoformatting:

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
  • babashka

    Native, fast starting Clojure interpreter for scripting

  • Not what you asked for but there is Babashka for scripting in Clojure.

    https://github.com/babashka/babashka

  • zfsbootmenu

    ZFS Bootloader for root-on-ZFS systems with support for snapshots and native full disk encryption

  • A lot of what's in the Pure Bash Bible is horrifically slow. Many of those things are substantially faster, even when paying the cost of starting a new process, when you use an external and commonly available tool. I wrote a bash performance profiler that outputs data in a format that flamegraph.pl recognizes - it really helped identify where we could improve the performance of ZFSBootMenu.

    https://github.com/zbm-dev/zfsbootmenu/releases/tag/v1.12.0

    Don't fall in the trap of thinking things have to be written entirely in bash; it's okay to use other tools to help fill in the gaps.

  • shellmath

    Yes, Virginia, you can do floating-point arithmetic in Bash!

  • There was a really awful and amazing floating point implementation posted here¹ a couple of years ago, with a few interesting comments too². I remember it in part because I was surprised there wasn't more discussion.

    ¹ https://github.com/clarity20/shellmath

    ² https://news.ycombinator.com/item?id=26250743

  • pfetch

    🐧 A pretty system information tool written in POSIX sh.

  • > does NetBSD sh or FreeBSD sh have them.

    Yes and yes. My FreeBSD machine has not even been updated in 5 years, if that helps.

    > What's the point of "pure sh" if it's restricted to specific versions of shells.

    The aforementioned features have been implemented for a very long time. The issues with old versions of dash I mentioned were crashes for very simple things, which is simply a bug rather than some fancy new-fangled feature that was yet to be implemented. Plus, the bible specifically listed workarounds for them.

    dylanaraps has quite a prolific collection of shell programs, and they run on a variety of operating systems. Most notably, pfetch[1] runs on Linux, Android, NetBSD, FreeBSD, OpenBSD, Minix, Haiku, macOS, Solaris and IRIX. I assure you that he is fully aware of the importance of compatibility.

    His pure Bash bible even has very thorough warnings for Bash versions required, since macOS uses Bash 3.2 (released in 2006) due to licensing reasons.

    [1] https://github.com/dylanaraps/pfetch

  • etc

    Things that are too small to keep in a separate repo, but too important not to version them. (by rollcat)

  • Depends on what you're trying to do. If you're shelling out to git(1) or docker(1), rather than e.g. recursively checking for the presence of .git in parent directories, or inspecting ~/.docker/config.json, then the fork+exec overhead is already quite significant. Next if you're parsing ~/.docker/config.json in shell, you're most likely either asking for trouble or (again) shelling out to jq. Writing it all in an interpreted language means you're paying the cost of interpreter startup, which on underpowered systems can take hundreds of milliseconds even when idle. OTOH loading a static binary to memory happens only once, and with Go you can trivially cross-compile.

    I also have a fallback shell one-liner, without any of the fanciness like displaying the current git branch:

    https://github.com/rollcat/etc/tree/master/cmd/prompter#i-li...

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts