Last active
August 29, 2015 13:57
-
-
Save pda/9498494 to your computer and use it in GitHub Desktop.
Bash argument grouping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./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