3 ms·
I almost always write POSIX shell instead of bash for compatibility; it would be nice to see collections for tips and tricks specifically for POSIX shell. I kno
by GolDDranks 6y ago
I almost always write POSIX shell instead of bash for compatibility; it would be nice to see collections for tips and tricks specifically for POSIX shell. I know, for example, that -o pipefail doesn't exist in plain POSIX shell. I wonder what's are the best practices when you can't use it.
- fpoling 6y agoI also write my scripts to stay /bin/sh compatible. If this is not enough, then a real scripting language should be used, not bash. But I very much agree that lack of pipefail is painful. If I know that output on the left of the pipe is small, I read it into a variable and then use printf | right part. If the output can be big, I use a helper function to emulate it that I copy-paste.
- asicsp 6y ago>it would be nice to see collections for tips and tricks specifically for POSIX shell Check out https://freebsdfrau.gitbook.io/serious-shell-programming/ https://freebsdfrau.gitbook.io/serious-shell-programming/
- sigzero 6y ago> it would be nice to see collections for tips and tricks specifically for POSIX shell https://www.shellscript.sh/ https://www.shellscript.sh/ There is a Facebook group and I have emailed the author as well with questions. Nice guy.
- m463 6y agook some low-grade tips: cleanup="true" later: if $cleanup; then a ; else b ; fi or slightly uglier $cleanup && rm -f mytempfile I like one-line functions: die() { echo "$@" 1>&2; exit 1; }
- peterwwillis 6y agoRead the ash or dash man pages and just use what they give you. That's pretty much Bourne shell which is pretty much POSIX.
- still_grokking 6y ago> -o pipefail doesn't exist in plain POSIX shell I think this changed lately[1]. No clue where's implemented, though. [1] https://www.austingroupbugs.net/view.php?id=789 https://www.austingroupbugs.net/view.php?id=789