bash unix set 命令集——“$@”“$i”的意思
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36207455/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
unix set command set -- “$@” "$i" meaning
提问by Teddy
I am confused for the one line bash script
我对一行 bash 脚本感到困惑
for i in "$@"
do
set -- "$@" "$i" // what does it mean?
done
I can understand $@ is all the variables which passing in, and i is every element which in $@, However, I can't figure what does
我可以理解 $@ 是传入的所有变量,而 i 是 $@ 中的每个元素,但是,我不知道是什么
set -- "$@" "$i"
means.
方法。
Thanks.
谢谢。
回答by chepner
It's appending the value of $i
onto the end of the positional parameters. Not sure whyone would want to do it, but it's basically a verbose way of doubling the parameters. It has the same affect as
它将 的值附加$i
到位置参数的末尾。不知道为什么要这样做,但它基本上是一种将参数加倍的冗长方式。它具有相同的影响
$ set -- a b c
$ echo "$@"
a b c
$ set -- "$@" "$@"
echo "$@"
a b c a b c