Re: [Help-bash] The difference between $* and "$*"?
From:
Seth David Schoen
Subject:
Re: [Help-bash] The difference between $* and "$*"?
Date:
Sat, 1 Feb 2014 10:58:32 -0800
User-agent:
Mutt/1.5.21 (2010-09-15)
Peng Yu writes:
> Hi,
>
> [...]
>
> I'm trying to understand the different between $* and "$*". The
> following shows that they behave differently when IFS is not the
> default. But the above paragraph from the manual does not explain
> this. Could anybody let me know if this is documented somewhere else
> in the manual and how to understand the difference? Thanks.
Hi,
The difference is whether it "expands to a single word" or to multiple
words.
#!/bin/bash
cd /tmp
echo "... this is the file with a space in its name" > "X Y"
echo "... this is the file X" > X
echo "... this is the file Y" > Y
set -- X Y
echo "Here is the unquoted version:"
cat $*
echo "Here is the quoted version:"
cat "$*"
In the two resulting invocations of cat, its argv argument arrays were,
first,
["/bin/cat", "X", "Y"]
and second
["/bin/cat/", "X Y"]
If IFS had been ":", the argv for cat would have been
["/bin/cat/", "X:Y"]
--
Seth David Schoen <address@hidden> | No haiku patents
http://www.loyalty.org/~schoen/ | means I've no incentive to
FD9A6AA28193A9F03D4BF4ADC11B36DC9C7DD150 | -- Don Marti