I'm having problems with getopts command.
When I want to use an option that requires the SAME argument, it stops running the program after the first option that requires an argument (-i for example). So when I want it to take the options -id or -i -d it will stop running the while loop after the "-i" option is used and ignore the -d option.
How can I get the loop to continue and for the -d option to execute as well?
The format for the arguments passed can be: "-id argument" or "-i -d argument"
I'm using $p currently to grab the final argument to pass for each option currently. this is linux ubuntu shell in dash:
To make the code smaller and quicker to read:
for p do :; done
echo arguments === $1 $2 $3
echo p = $p
while getopts ":hva:b:d:g:i:u:w:" opt;
do
case "$opt" in
i)
checkdir $p
fileinfo $p
;;
***OTHER OPTIONS FOLLOW SIMILAR FORMAT***
esac
done
When I want to use an option that requires an argument, it stops running the program after the first option that requires an argument (-i for example). So when I want it to take the options -id or -i -d it will stop running the while loop after the "-i" option is used.
If you want it to take the options … -i -d , you have to (since each of them requires an argument ) supply an argument right after each option, eg … -i argument1 -d argument2 …
.
With -id
or -i -d
the d
or -d
, respectively, is taken for the option's argument.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.