我正在运行 bash 版本 4.2,并尝试使用内置命令
脚本在这里:
getopts
解析命令行参数,但是 getopts 似乎无法正确解析,如果 -s
不是第一个参数,它将不会被解析。
-s
没有被解析:%> ./getopt.sh aaa -s aaa
aaa
这个会被解析
%> ./getopt.sh -s aaa
s: aaa
aaa
脚本在这里:
#!/bin/bash
while getopts "bs:" opt
do
case $opt in
s)
echo "s: $OPTARG"
;;
*)
echo not supported
;;
esac
shift
done
echo $1
--
。 - user539810