2

I created a bash script and i need help with getopts

Each options have arguments :

while getopts ":a:b:c:" opt
do
case $opt in
  a)  echo "$OPTARG";;
  b)  echo "$OPTARG";;
  c)  echo "$OPTARG";;
  /?) echo "wrong option $OPTARG";;
esac
done

If i want to use the same argument, i need to type -option arg for each options

./script.sh -a hello -b hello -c hello

hello
hello
hello

I would like to be able to use the script like a command, typing options all together when i have the same argument :

./script.sh -abc hello

Unfortunately bc is now the argument :

bc

Does anyone could help me please ?

Regards,

jww
  • 97,681
  • 90
  • 411
  • 885
  • The `getopts` system doesn't allow that. If an option needs an argument, then it should be specified independently. – codeforester Mar 30 '18 at 15:18

0 Answers0