小编Alt*_*lta的帖子

检测 getopts `--` (双破折号)以发出消息

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)

bash getopts arguments

0
推荐指数
2
解决办法
5514
查看次数

标签 统计

arguments ×1

bash ×1

getopts ×1