如何使用 getopts 获取参数的值

How to get value of argument in with getopts

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

对于上面的代码段,执行时

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

结果进入

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

如我所料

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

我做错了什么?

只有一个字错了。这是更正后的版本:

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

您将 OPTARG 拼错为 OPTORG