Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #14110

Documentation for a="$@"

From Ilkka Virta <itvirta@iki.fi>
Newsgroups gnu.bash.bug
Subject Documentation for a="$@"
Date 2018-05-19 22:40 +0300
Message-ID <mailman.88.1526758841.1292.bug-bash@gnu.org> (permalink)

Show all headers | View raw


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 / itvirta@iki.fi

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Documentation for a="$@" Ilkka Virta <itvirta@iki.fi> - 2018-05-19 22:40 +0300

csiph-web