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 parameters, and $i is one of the positional parameters. However, I can't figure out what

set -- "$@" "$i" 

means.

0

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 
0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like