bash输出无效选项

| 说我有以下脚本来处理选项:
while getopts dsf opts 2>/dev/null
do
    case $opts in
    d) echo \"d\";;
    s) echo \"s\";;
    \\?) echo \"Error: An invalid option [?] was entered.\";
        exit 1;;
    esac
done
我想用输入的无效开关替换[?]。 所以如果我输入
./myscript -z //output: Error: An invalid option [-z] was entered.
我将如何捕获该无效开关?使用$ opts变量显示一个问号。     
已邀请:
来自
help getopts
getopts reports errors in one of two ways.  If the first character
of OPTSTRING is a colon, getopts uses silent error reporting.  In
this mode, no error messages are printed.  If an invalid option is
seen, getopts places the option character found into OPTARG.
    

要回复问题请先登录注册