Say, I have a script that gets called with this line:
or this one:
What's the accepted way of parsing this such that in each case (or some combination of the two) $v, $f, and $d will all be set to true and $outFile will be equal to /fizz/someOtherFile ?
Preferred Method: Using straight bash without getopt[s]
I originally answered the question as the OP asked. This Q/A is getting a lot of attention, so I should also offer the non-magic way to do this. I'm going to expand upon guneysus's answer to fix the nasty sed and include Tobias Kienzler's suggestion. Two of the most common ways to pass key value pair arguments are:
Straight Bash Space Separated
Straight Bash Equals Separated
Never use getopt(1). getopt cannot handle empty arguments strings, or arguments with embedded whitespace. Please forget that it ever existed. The POSIX shell (and others) offer getopts which is safe to use instead. Here is a simplistic getopts example:
The advantages of getopts are:
The disadvantage of getopts is that it can only handle short options (-h, not --help) without trickery. There is a getopts tutorial which explains what all of the syntax and variables mean. In bash, there is also help getopts, which might be informative.