小编Ahm*_*hah的帖子

如何在 Bash 中使用带有长选项的 getopt?

我在 Bash 中有以下代码:

declare {BPM_USERNAME,BPM_PASSWORD,HOST,TARGET_IP,OVERRIDE_STATUS}=''
OPTS=`getopt -a --longoptions username:,password:,csc:,ip:,override: -n "$0" -- "$@"`
eval set -- "$OPTS"

if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi

while true; do
    echo ""
    echo $OPTS
    echo $1
    echo $2

  case "$1" in
    --username )
        BPM_USERNAME=$2
        shift 2
        ;;
    --password )
        BPM_PASSWORD=$2
        shift 2
        ;;
    --csc )
        HOST=$2
        shift 2
        ;;
    --ip )
        TARGET_IP=$2
        shift 2
        ;;
    --override )
        OVERRIDE_STATUS=$2
        shift 2
        ;;
    --) …
Run Code Online (Sandbox Code Playgroud)

bash getopt command-line-arguments

1
推荐指数
1
解决办法
4494
查看次数

标签 统计

bash ×1

command-line-arguments ×1

getopt ×1