我在使用引用变量调用脚本中的脚本时遇到了麻烦。
#!/bin/sh
while getopts c:a: optionalargs
do
case $optionalargs in
c)copt=$OPTARG;;
a)aopt=$OPTARG;;
*)echo "Invalid arg";;
esac
done
if [ ! -z "$copt" ]
then
export CHAR_SET=$copt
fi
if [ ! -z "$aopt" ]
then
export ADDITIONAL_FLAGS=$aopt
fi
shift $((OPTIND -1))
/var/bin/script1.sh "${CHAR_SET}" "${ADDITIONAL_FLAGS}"
结果:
当使用带引号的/var/bin/script1.sh "${CHAR_SET}" "${ADDITIONAL_FLAGS}"
时
./a.sh -a additional -c character
too many arguments . Use -h for help
当使用没有引号的/var/bin/script1.sh ${CHAR_SET} ${ADDITIONAL_FLAGS}
时
./a.sh -a additional -c character
script runs fine
题:
为什么双引号会失败我的脚本?它应该不会阻止全球化吗?
在内部调用的脚本中发现了该问题。它处理双引号参数并替换为单引号。所以,这真的不是问题。