getopts
我正在使用通过名为 的变量使用的惯用方式arg
。我可以捕获选项名称,如下所示。是否可以检测 getopts 到达“--”的时刻,以便我可以发出消息?
while getopts "$shortopts" arg; do
echo "--> arg: $arg"
case $arg in
("V")
printf '%s\n' "Version"
return
;;
("u")
printf '%s\n' "Usage"
return
;;
("h")
printf '%s\n' "Help"
return
;;
esac
done
Run Code Online (Sandbox Code Playgroud)