3 ms·
> I've learned a lot of tricks and I'm very tempted to write a second "bible" with snippets that are supported in all POSIX shells. That could be potentially e
by acqq 7y ago
> I've learned a lot of tricks and I'm very tempted to write a second "bible" with snippets that are supported in all POSIX shells.
That could be potentially even more interesting than a bash-specific one (as it is harder to get it right -- bash can be figured out out of the single reference, anything "portable" has many dependencies).
- dyanaraps 7y agoOff the top of my head, a few notable things I've learned: - Safely working with "string lists" (list="el el el el"). - Filtering out duplicate items. - Reversing the list. - etc. - Using `case` to do sub-string matching (using globbing). - Using `set -- el el el` to create an "array" (only one array at a time!). - `read -r` is still powerful in POSIX `sh` for getting data out of files. `while read -r` even more so. - POSIX `sh` has `set -e` and friends so you can exit on errors etc. - Ternary operators still exist for arithmetic (`$(($# > 0 ? 1 : 0))`). - Each POSIX `sh` shell has a set of quirks you need to account for. What works in one POSIX `sh` shell may not in another. (I found a set of differences between `ash`/`dash` in my testing). POSIX `sh` is a very simple language compared to `bash` and all of its extensions so there won't be as many snippets but there's some gold to be found.
- dyanaraps 7y agoI've started working on it here: https://github.com/dylanaraps/pure-sh-bible https://github.com/dylanaraps/pure-sh-bible
- acqq 7y agoI see you already made progress there! Congratulations!