== I need to use _getopts_ sooner (and more often) in Bourne shell scripts I have this flaw in my Bourne shell scripting; in shell scripts and shell scripts alone, I find it all too easy and tempting to reach for ad-hoc option processing when I add the first option to a script. Inevitably, handling the first option will look something like: .pn prewrap on > [...] > SOMEVAR=0 > if [ "$1" = "-L" ]; then > SOMEVAR=1; shift > fi > [...] When a second option shows up, it sometimes winds up getting wedged awkwardly into the same sort of code. Maybe the options conflict so they'll never get used together in practice, or I'll tell myself that I'll always remember the order, or some equally bad excuse. Doing this is a mistake, and I need to accept that. Rather than ever writing ad-hoc option processing code, I should be using _getopts_ in my scripts right from the start even in tiny little scripts. Even using _getopts_ for a single option is not that much more code over the simple version above, and it has better error handling. And of course, adding more options is much simpler and works much better if I'm using _getopts_ already. (Probably I should just memorize and master a standard _getopts_ stanza so I can drop it into everything by reflex. But that's going to take time, and also not reflexively reaching for the quick solution for single options.) I'm not entirely sure why I'm so reluctant in practice to use _getopts_, but for whatever reason it's not part of my shell landscape most of the time. This is silly, as _getopts_ has existed for a long time and is [[a Single Unix Specification standard http://pubs.opengroup.org/onlinepubs/9699919799/utilities/getopts.html]]. As a practical matter it's long since been supported everywhere that I'm ever going to run a shell script. I need to get with the times and update my Bourne shell habits. (This entry is brought to you by me updating some scripts today, trying to add a second option to them in a terrible way, and then telling myself that I should be doing this right and switching them over to using _getopts_. The resulting shell script code is both better and shorter.)