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.
How will catch that invalid switch?使用我的 $opts 变量会显示一个问号。
Say I have the following script to handle options:
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
I want to replace the [?] with the invalid switch I entered.
So if I enter
./myscript -z //output: Error: An invalid option [-z] was entered.
How would I catch that invalid switch? Using my $opts variable displays a question mark.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自
help getopts
:From
help getopts
: