What Does Set -- “$@” "$I" Mean in Bash?
The Set Command in the Following Loop Is Confusing to Me. for I in "$@" Do Set -- "$@" "$I" # What Does It Mean? Done I Can Understand $@ Is All the Positional...
The set command in the following loop is confusing to me.
for i in "$@"
do
set -- "$@" "$i" # what does it mean?
done
I can understand $@ is all the positional parameters, and $i is one of the positional parameters. However, I can't figure out what
set -- "$@" "$i"
means.
1 Answer
It's appending the value of $i onto the end of the positional parameters. Not sure why one would want to do it, but it's basically a verbose way of doubling the parameters. It has the same affect as
$ set -- a b c
$ echo "$@"
a b c
$ set -- "$@" "$@"
echo "$@"
a b c a b c