How do I handle switches in a shell script?
Most common shell commands allow the user to specify options in any random order. Positional Parameters like
$1 as commonly used in bash (I tend to write all my scripts in Bash but I don't think this question is actually Bash specific) scripts on the other hand, are order specific.
Now I could come up with some way to remove the need for the user of a bash script to observe any particular order in the supplying of optional arguments. (Using regular expressions or globs to test for the presence of some particular option in the
$@ expansion comes to mind.) However, I am really trying to find out whether there is a particularly canonical way to implement such options. Given the common syntax for options like
-r for many shell commands I certainly feel there should be.