[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Documentation for a="$@"

From: Ilkka Virta
Subject: Documentation for a="$@"
Date: Sat, 19 May 2018 22:40:24 +0300
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Thunderbird/52.7.0

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 / address@hidden

reply via email to

[Prev in Thread] Current Thread [Next in Thread]