0
while getopts ':s:e:ci:z:n:d:m:' opt; do
  echo -- $opt
  echo -- $OPTORG
done

For The above snippet when executed with

bash a.sh -c -m lsdjfe -s "all ab" -d all

Results into

-- c
--
-- m
--
-- s
--
-- d
--

Where as i was expecting

-- c
--
-- m
-- lsdjfe
-- s
-- all ab
-- d
-- all

What am i doing wrong?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
codeofnode
  • 18,169
  • 29
  • 85
  • 142

1 Answers1

1

Only one character was wrong. This is the corrected version:

while getopts ':s:e:ci:z:n:d:m:' opt; do
  echo -- $opt
  echo -- $OPTARG
done

You misspelled OPTARG as OPTORG.

Mike Slinn
  • 7,705
  • 5
  • 51
  • 85