3 ms·
No, $@ 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,
by hibbelig 11y ago
No, $@ 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.