What does HackerNews think of pure-sh-bible?

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

Language: Shell

#13 in Shell
The same amazing guy also published the Pure sh Bible: https://github.com/dylanaraps/pure-sh-bible
There's also these resources for more vetted patterns:

(1) Bash: https://github.com/dylanaraps/pure-bash-bible

(2) POSIX Shell: https://github.com/dylanaraps/pure-sh-bible

This pairs extremely well with dylan's Pure Bash/sh Bible [1], both, combined with admittedly way too many hours browsing random people's dotfiles can exponentially increase your skills with shells scripting.

Some tips of my own:

Adding `2>/dev/null` or `>/dev/null 2>&1`after most commands with expected or just plain useless output can make writing headless scripts very easy, it also comes in very handy when trying to shut up some basic utilities.

A handy function:

  execute() {
 pkill -x "$1"
 {
  sleep 0.1
  "$@" &
 }
  } >/dev/null 2>&1
`set --` before running a command can be used to remove all excess whitespace (making parsing dead easy).

And last but not least always using printf instead of echo makes your scripts 1000x cooler :)

0. https://github.com/dylanaraps/pure-sh-bible 1. https://github.com/dylanaraps/pure-bash-bible

Dylan is also the author of KISS Linux and the pure {sh,bash} bibles. All interesting projects.

https://k1sslinux.org/ https://github.com/dylanaraps/pure-sh-bible

I used to think that way, but POSIX is not that well specified and there are tons of little behavior changes that makes the task difficult past 10 lines of code. Writing portable shell scripts is like writing portable JavaScript in the IE days.

https://github.com/dylanaraps/pure-sh-bible is a good example if you look at the issue tracker.

Once you accept Bash as a standard things become much easier. Basically Bash arrays, the `@Q` notation and ShellCheck combined solve all of the escaping issues that plague shell scripts.

While you're at it, for a similar resource check out: https://github.com/dylanaraps/pure-bash-bible and https://github.com/dylanaraps/pure-sh-bible

I believe they've been posted here previously.

I use POSIX /bin/sh exclusively. It's reasonably lightweight but because of this you loose a lot of the "bash-ism"s. There's ways to work around it though, and the pure-sh-bible[1] is great.

1: https://github.com/dylanaraps/pure-sh-bible

> You can add me to those interested in a pure POSIX shell bible.

I've started working on it here: https://github.com/dylanaraps/pure-sh-bible

> are there any bashisms that are truly essential and you don't want to live without?

The only thing I'd say I miss when writing POSIX `sh` is arrays.

I work around this by using 'set -- 1 2 3 4' to mimic an array using the argument list. The limitation here though is that you're limited to one "array" at a time.

The other alternative I make use of is to use "string lists" (list="1 2 3 4") with word splitting.

This can be made safe if the following is correct:

- Globbing is disabled.

- You control the input data and can safely make assumptions (no spaces or new lines in elements).

While it's something that'd be nice to have, there are ways to work around it.

EDIT: One more thing would be "${var:0:1}" to grab individual characters from strings (or ranges of characters from strings).