The code that I already have parses only the first argument after -r (i.e. roi1). What do I have to change in order to parse all the arguments after the flag -r?
you can put quotes around the multiple arguments, the the shell would pass them through as one (and getopt should do the same)
or have mutltiple -r statements and alter the code to add to the roi variable rather than overwriting it
Yes, this makes sense... I tried before the double quotes and it worked... but I was wondering if there was a way to do this without the double quotes...
well you could monkey with the IFS variable in bash, but that would throw up even more headaches. Basically, you need to stop the shell from reading the spaces as spaces (i.e. field seperators) so you could also quote each individual space by backslashing it.
I think the easiest way is to enforce multiple -r <option> on the command line, and alter the code accordingly.
you could ditch the -r requirement and have it's options as the last parameters on the command line.
while getopts "i:f:r:" OPTION
do
case $OPTION in
i) iter=$OPTARG;;
f) frame=$OPTARG;;
?) echo Usage: ......
exit 2;;
esac
done
# remove any arguments found so far
shift $(($OPTIND - 1))
# here roi will be the remaining arguments on the command line
roi="'$*'"
the roi variable will now have the rest of the command line, so if it was called thus:
application -i 2 -f 3 roi1 roi2 roi3
then the output would be:
$iter==2
$frame==3
$roi=='roi1 roi2 roi3'
and if you didn't want the roi variable to be quoted, as I have it here, then remove the single quotes around '$*' on the line in red above.
Hope this helps, and never give up, it is never tooooo difficult.