3 ms·
Treating shell scripts as first class has taken me on a bit of a journey over the last decade: - Learned from shunit2 that it's possible to write solid shell s
by l0b0 5y ago
Treating shell scripts as first class has taken me on a bit of a journey over the last decade:
- Learned from shunit2 that it's possible to write solid shell scripts, and that writing test code in shell scripts is hard to learn but doable. Bonus: I'd rather write the test script in a more easily debuggable language, such as Python.
- Bash has many more surprises in store for you than any other mainstream language. How $IFS affects things, how looping over files is either completely trivial (`for file in *`) or damn near impossible (`while IFS= read -d '' -r -u 3; do …; done 3< <(find … -exec printf '%s\0')`) based on the pattern you want to match, exit codes of arithmetic assignments, all the tricks to deal with not having exceptions, how `ls` is unsuitable for scripting despite being ubiquitous, locales, variable flags, and so on.
- `shellcheck` is fantastic, especially for including URLs to more information about each warning.
- Greg's Wiki[0], despite being hard to find in search engines, is the best place by far for learning about Bash.
- Writing a shell script to do some fast, asynchronous processing is maybe 30-100 times faster than writing the same in Python, but getting the nitty-gritty details right is about 30-100 times harder as well.
[0] https://mywiki.wooledge.org/ https://mywiki.wooledge.org/