Created
November 19, 2010 19:56
-
-
Save mernen/707045 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # let's define this (bash) function to help us see what's happening: | |
| args() { echo "${#@} arguments:"; for arg in "$@"; do echo "-> $arg"; done; } | |
| # now let's see the differences between $@ and $*: | |
| # $*: expands into a series of words, basically ignoring all the quotes | |
| # you'll hardly ever want to do this | |
| test() { args $*; } | |
| test a "b b" c | |
| # will echo 4 arguments: a, b, b, c | |
| # $@: the exact same as $* | |
| test() { args $@; } | |
| test a "b b" c | |
| # will echo 4 arguments: a, b, b, c | |
| # "$*": expands into a single argument, joining original arguments with spaces | |
| # possibly even less useful than $* | |
| test() { args "$*"; } | |
| test a "b b" c | |
| # will echo 1 argument: a b b c | |
| # "$@": expands into the proper original arguments | |
| # that's the sane one | |
| test() { args "$@"; } | |
| test a "b b" c | |
| # the same rules apply to array-type variables, but syntax is ridiculous | |
| # e.g.: given an array foo, use: ${foo[*]} ${foo[@]} "${foo[*]}" "${foo[@]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment