What does HackerNews think of pure-sh-bible?
📖 A collection of pure POSIX sh alternatives to external processes.
(1) Bash: https://github.com/dylanaraps/pure-bash-bible
(2) POSIX Shell: https://github.com/dylanaraps/pure-sh-bible
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
https://k1sslinux.org/ https://github.com/dylanaraps/pure-sh-bible
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.
I believe they've been posted here previously.
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).