The unix set command set is "$ @" "$ i", which means

I am confused in a single line bash script

for i in "$@"
do 
  set -- "$@" "$i" // what does it mean?
done

I can understand that $ @ is all the variables that are passed, and I am every element that is in $ @. However, I can’t understand what makes

    set -- "$@" "$i" 

facilities.

Thank.

+4
source share
1 answer

It adds value $ito the end of positional parameters. Not sure why this is necessary, but it is basically a verbose way to double the parameters. It has the same effect as

$ set -- a b c
$ echo "$@"
a b c
$ set -- "$@" "$@"
echo "$@"
a b c a b c
+11
source

All Articles