Post #1820189
2026-04-30 03:41 UTC
I wish I could convince more people writing bash scripts¹ to start with a getopts block, then add a $usage variable above getopts that's printed in response to -h/--help, then a block of default variables & values above that which can be included in the help text, then a `set -o nounset -o pipefail -o errexit`² above that, then a function to trap ONEXIT that cleans up temp files & dirs.
1/2
¹: yes, bash, the vast majority interpreter; though I respect sh and love ksh93
²: which requires care
Replies (2)
-
@gnomon@mastodon.social 2026-04-30 03:44
This isn't "the one true way to write bash scripts" or anything, it's just table stakes - a common progression that helps clarify intent and design early, at the point when a script might *just* be useful enough that the implementer then moves on to higher priority tasks and doesn't look at the script again for nine years. (There are more steps later of course, like consistent error checking & handling, logging with priority levels & verbosity control, and of course shellcheck(1). Later.) 2/2
-
@jbowen@mast.hpc.social 2026-04-30 19:56
@gnomon@mastodon.social csh forever!