我有一个
shell脚本,我传递的参数很少.
Test1.sh -a 1 -b 2 -c“One Two Three”
在Test1.sh里面我以下面的方式调用另一个shell脚本. Test2.sh $*
我想将所有参数传递给Test2,它们传递给Test1,并且格式相同(使用双引号等). 但是传递给Test2的参数是 Test2.sh -a 1 -b 2 -c一二三 哪个对我不起作用.有没有办法绕过它,以便我可以传递参数的方式与传递给Test1的方式相同.
谢谢 扎比
解决方法
你需要说:
Test2.sh "$@"
参见Special Parameters:
@
Expands to the positional parameters,starting from one. When the expansion occurs within double quotes,each parameter expands to a separate word. That is,"$@" is equivalent to "$1" "$2" ... . If the double-quoted expansion occurs within a word,the expansion of the first parameter is joined with the beginning part of the original word,and the expansion of the last parameter is joined with the last part of the original word. When there are no positional parameters,
"$@" and $@ expand to nothing (i.e.,they are removed).
手册说:
"$*" is equivalent to "$1c$2c..." ,where c is the first character of the value of the IFS variable.
这解释了你正在观察的结果.
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|