Skip to content

Instantly share code, notes, and snippets.

@pda
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pda/9498494 to your computer and use it in GitHub Desktop.
Save pda/9498494 to your computer and use it in GitHub Desktop.
Bash argument grouping
#!/bin/bash
A=("$@")
X="$@"
echo; echo '"$@": <-- correct'
for arg in "$@"; do echo "$arg"; done
echo; echo '"${A[@]}": <-- correct'
for arg in "${A[@]}"; do echo "$arg"; done
echo; echo '"$X": <-- nope'
for arg in "$X"; do echo "$arg"; done
$ ./test.sh one "two three"
"$@": <-- correct
one
two three
"${A[@]}": <-- correct
one
two three
"$X": <-- nope
one two three
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment