4 ms·
Wildcards are not variables. Wildcards don't get expanded in quotes. Variables get expanded in double quotes but not single quotes. $@ obeys all the same expans
by adrusi 11y ago
Wildcards are not variables. Wildcards don't get expanded in quotes. Variables get expanded in double quotes but not single quotes. $@ obeys all the same expansion rules as all other variables. Command substitution with both $() and `` follow the same rules as variables.
- kazinator 11y ago> $@ obeys all the same rules as all other variables. That's hardy the case. Most other variables do not represent the positional parameters, and don't have the logic of "$@" which effectively produces "$1" "$2" "$3" ...
- adrusi 11y agoI was refering to the expansion behavior, which was the point in contention. I've clarified the original comment.
- hibbelig 11y agoNo, $@ is special where $* is regular. Consider the following script foo.sh and call it like so: ./foo.sh one "a b" two The $* part will print one line, the $@ part will print three lines. #!/bin/bash for x in "$*"; do echo $x done for x in "$@"; do echo $x done I use "$@" often, but to this day I don't fully understand how $@ works...
- kazinator 11y agoUnquoted $@ works exactly like unquoted $* . Quoted "$* " separates the parameters using the first character stored in IFS, or with nothing if IFS is unset/null. Usually, the first character of IFS is space, giving the impression that "$* " means "separate with spaces"; i.e. that it's just an ordinary quote job around $* (i.e. that it is "regular", in your words). Quoted "$@" does ... what you clearly understand.