Using getopts within user-defined-function in bourne shell Using getopts within user-defined-function in bourne shell shell shell

Using getopts within user-defined-function in bourne shell


You can provide args to getopts after the variable. The default is $@, but that's also what shell functions use to represent their arguments. Solution is to pass "$@" — representing all the script's command-line arguments as individual strings — to processArgs:

processArgs "$@"

Adding that to your script (and fixing the quoting in line 11), and trying out some gibberish test args:

$ ./try -j asdf -f fooo -fasdfasdf -j424pyagnasdj -- asdff -- foooJob number asdf already set.Filename fooo will be ignored.f -- asdfasdfJob number asdf already set.Filename asdfasdf will be ignored.j -- 424pyagnasd