I am trying to write a wrapper shell script that caches information every time a command is called. It only needs to store the first non-option argument. For example, in
$ mycommand -o option1 -f another --spec more arg1 arg2
I want to retrieve “arg1.”
How can this be done in bash?
Using getopt is probably the way to go.
If you wanted to see argument scanning code in bash, the non-getopt way is: