bash tools for parsing arguments
- by BCS
I have a bash script that uses a few variables (call them $foo and $bar). Right now the script defines them at the top with hard coded values like this:
foo=fooDefault
bar=barDefault
....
# use $foo and $bar
What I want is to be able to use the script like any of these:
myscript # use all defaults
myscript -foo=altFoo # use default bar
myscript -bar=altBar # use default foo
myscript -bar=altBar -foo=altFoo
An ideal solution would allow me to just list the variable that I want to check for flags for.
Is there a reasonably nice way to do this?
I've seen getopt and I think it might do about 70% of what I'm looking for but I'm wondering if there is a tool or indium that builds on it or the like that gets the rest.