3 ms·
You can add me to those interested in a pure POSIX shell bible. Whenever I'm about to write a moderately large script, I'm actively avoiding bashisms as they do
by tannhaeuser 7y ago
You can add me to those interested in a pure POSIX shell bible. Whenever I'm about to write a moderately large script, I'm actively avoiding bashisms as they don't buy me much yet make my script unportable. But, given you've spent so much time on this subject, are there any bashisms that are truly essential and you don't want to live without?
- dyanaraps 7y ago> 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 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).
- akdor1154 7y agoset -o pipefail
- scbrg 7y agoThat, and local variables. I avoid bash for the same reasons as GP, so I tend to (reluctantly) live without pipefail and work around the lack of local variables with subshells (which I assume has a performance impact - but hey).