0

What's is the meaning of @ in the following code excerpt from mariadb docker image entrypoint

...
SOCKET="$(_get_config 'socket' "$@")"
"$@" --skip-networking --socket="${SOCKET}" &
pid="$!"

mysql=( mysql --protocol=socket -uroot -hlocalhost --socket="${SOCKET}" )

for i in {30..0}; do
    if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then
        break
...

Would be happy to get a reference to good manual/reference to bash, as searching in google for @ meaning in bash couldn't produce good results.

rok
  • 9,403
  • 17
  • 70
  • 126
  • $@ will hold the parameters that are passed to a given script. So for example with ./test test test1, $@ will hold "test test1" – Raman Sailopal May 15 '17 at 09:13
  • references: Bash's manual: [special parameters (`$@`)](https://www.gnu.org/software/bash/manual/html_node/Special-Parameters.html#Special-Parameters), [arrays (`${mysql[@]}`)](https://www.gnu.org/software/bash/manual/html_node/Arrays.html) and [BashGuide](http://mywiki.wooledge.org/BashGuide) – ilkkachu May 15 '17 at 21:09

1 Answers1

3

The GNU man bash page would be a good place to start

@

($@) Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, each parameter expands to a separate word. That is, "$@" is equivalent to "$1" "$2" …. If the double-quoted expansion occurs within a word, the expansion of the first parameter is joined with the beginning part of the original word, and the expansion of the last parameter is joined with the last part of the original word. When there are no positional parameters, "$@" and $@ expand to nothing (i.e., they are removed).

A small example to demonstrate the same,

function foo() {
    printf "%s\n" "$@"
}

foo 1 2 3

would print

1
2
3
Community
  • 1
  • 1
Inian
  • 80,270
  • 14
  • 142
  • 161