1

这是我的shell脚本-

if ! options=$(getopt -o : -l along:,blong:,clong: -- "$@")
then
    # something went wrong, getopt will put out an error message for us
    exit 1
fi

set -- $options

while [ $# -gt 0 ]
do
    case $1 in
        --along) echo "--along selected :: $2" ;;
        --blong) echo "--blong selected :: $2" ;;
        --clong) echo "--clong selected :: $2" ;;
    esac
    shift
done

当我运行脚本时,我得到以下输出 -

./test.sh --along hi --blong hello --clong bye
--along selected :: 'hi'
--blong selected :: 'hello'
--clong selected :: 'bye'

问题是我不想用单引号('hi','hello','bye')显示参数。我应该怎么做才能摆脱那些引号?

4

1 回答 1

5

使用选项-u--unquoted用于getopt,即

if ! options=$(getopt -u -o : -l along:,blong:,clong: -- "$@")

getopt 的联机帮助页说-u

不要引用输出。请注意,空格和特殊(依赖于 shell)字符可能会在此模式下造成严重破坏(就像它们对其他 getopt(1) 实现所做的那样)。

于 2012-12-07T11:17:31.937 回答