Re:Use the Unofficial Bash Strict Mode (Unless You Love Debu...
by ianbicking on Friday March 18, 2016 @04:42PM
(#11314818)
That's right for $@, but AFAIK only $@ – for instance you can't do:
[ Parent
| on HN ]
Re:Use the Unofficial Bash Strict Mode (Unless You Love Debu...
by kazinator on Friday March 18, 2016 @05:16PM
(#11315124)
for filename in *.txt ; do ...
has no issue with spaces in filenames. If *.txt matches "foo bar.txt", then that's what the filename variable is set to. In the body of the loop you have to make sure you have "$filename".You don't need play games with IFS to correctly process filesystem entry names expanded from a pattern.
Re:Use the Unofficial Bash Strict Mode (Unless You Love Debu...
by adrusi on Friday March 18, 2016 @04:57PM
(#11314963)
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.
Re:Use the Unofficial Bash Strict Mode (Unless You Love Debu...
by hibbelig on Friday March 18, 2016 @05:39PM
(#11315347)
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...
Re:Use the Unofficial Bash Strict Mode (Unless You Love Debu...
by kazinator on Friday March 18, 2016 @05:51PM
(#11315450)
Unquoted $@ 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.
Re:Use the Unofficial Bash Strict Mode (Unless You Love Debu...
by kazinator on Friday March 18, 2016 @05:24PM
(#11315203)
> $@ 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" ...