Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash getopt不带引号地传递参数_Bash_Shell_Unix - Fatal编程技术网

Bash getopt不带引号地传递参数

Bash getopt不带引号地传递参数,bash,shell,unix,Bash,Shell,Unix,这是我写的bash脚本: if ! options=$(/usr/local/opt/gnu-getopt/bin/getopt -o hro: -l help,reuse,outdir: -- "$@") then # something went wrong, getopt will put out an error message for us exit 1 fi while [ $# -gt 0 ] do case $1 in -r|--reuse) c

这是我写的bash脚本:

if ! options=$(/usr/local/opt/gnu-getopt/bin/getopt -o hro: -l help,reuse,outdir: -- "$@")
then
    # something went wrong, getopt will put out an error message for us
    exit 1
fi

while [ $# -gt 0 ]
do
    case $1 in
    -r|--reuse) cmd_options=--reuse-last-results ;;
    -h|--help) usage;;
    -o|--outdir) out_dir=$2; shift;;
    (--) shift; break;;
    (-*) echo "$0: error - unrecognized option $1" 1>&2; exit 1;;
    (*) break;;
    esac
    shift
done
问题是我用引号获取out_dir的值。 例如:

test.sh --outdir ./here -r 

echo$outdir
显示为
。/here'
。请建议如何删除引号。

您可以使用
${1/'/}
而不是
$1
。这将扩展参数
$1
,并删除单引号。使用util linux 2.20.1中的
getopt和
bash版本4.2.37(1)
,问题不会出现。