What is $ @ in Bash?

I believe that the $@ descriptor in a shell script is an array of all the arguments given by the script. It's true?

I ask because I usually use search engines to collect information, but I can’t google for $@ , and I have become too ordinary to easily get everything.

+50
bash arguments
Oct 10 2018-10-10T00:
source share
2 answers

Yes. See the bash man page (the first thing you go to) under Special Options

Special parameters

The shell considers several parameters. These parameters include only links; assignment to them is not permitted.

* Expands to positional parameters, starting with one. When expansion occurs in double quotes, it expands to one word with the value of each parameter separated by the first character of the IFS special variable. That is, "$*" equivalent to "$1c$2c..." , where c is the first character of the value of the IFS variable. If IFS is not specified, parameters are separated by spaces. If IFS is null, the parameters are combined without intermediate delimiters.

@ Expands to positional parameters, starting from one. When expansion occurs in double quotes, each parameter expands to a single word. That is, "$@" equivalent to "$1" "$2" ... If double quotation decomposition occurs inside a word, the decomposition of the first parameter is connected to the initial part of the original word, and the decomposition of the last parameter is connected to the last part of the original word. When there are no positional parameters, "$@" and $@ expand to zero (that is, they are deleted).

+46
Oct 10 '10 at 1:53
source share

Just by reading, I would never understand that "$@" extends to a list of individual parameters. While "$*" is a single parameter, consisting of all parameters added together.

If that still doesn't make sense, do it.

http://www.thegeekstuff.com/2010/05/bash-shell-special-parameters/

+15
Jun 03 '15 at 20:20
source share



All Articles