In Bash, using "$@" in an assignment, (as in a="$@" ) concatenates the positional parameters to single string, joined with spaces. Somewhat similarly to what "$*" does, except that $* uses the first letter of IFS, but $@ always uses a space.

However, I can't see this documented in the manual, is it somewhere?


"3.4 Shell Parameters" [1] discusses assignments to variables, and there's the phrase: "Word splitting is not performed, with the exception of "$@" as explained below." But the actual explanation seems to be missing, as there's no other mention of $@ on the page.

There's also no mention of assignments under "3.4.2 Special Parameters" [2]. It simply states that "$@" expands to separate words.


I'd suggest adding something like this to the description of $@ in 3.4.2:

""
If $@ or "$@" is used on the right hand side of an assignment to a variable, it instead expands to a single word with the value of each positional parameter separated by a space. That is, a="$@" is equivalent to a="$1 $2 ...".
""



(It seems the online manual is an older version than that in git, but I didn't see this mentioned in the devel version of the manual either.)


[1] https://www.gnu.org/software/bash/manual/html_node/Shell-Parameters.html
[2] https://www.gnu.org/software/bash/manual/html_node/Special-Parameters.html


--
Ilkka Virta / itvi...@iki.fi

Reply via email to