Bash getopt不带引号地传递参数
这是我写的bash脚本: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
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)
,问题不会出现。