f



why "" in echo "$FOO" ?


I just read in a book that to one way to find out the value of an
enviroment variable is to give it as the argument to echo, preceded
by a $ and surrounded by double quotes, as in echo "$FOO".  Why
the quotes?  It seems that I get the same results whether I do echo
$FOO or echo "$FOO".

Thanks!

	Karl

-- 
Sent from a spam-bucket account; I check it once in a blue moon.  If
you still want to e-mail me, cut out the extension from my address,
and make the obvious substitutions on what's left.
0
KKramsch
11/28/2004 6:24:44 AM
comp.unix.shell 15484 articles. 3 followers. Post Follow

4 Replies
727 Views

Similar Articles

[PageSpeed] 36

KKramsch <karlUNDERSCOREkramsch@yahooperiodcom.invalid> wrote:
> 
> 
> I just read in a book that to one way to find out the value of an
> enviroment variable is to give it as the argument to echo, preceded
> by a $ and surrounded by double quotes, as in echo "$FOO".  Why
> the quotes?  It seems that I get the same results whether I do echo
> $FOO or echo "$FOO".
> 
> Thanks!
> 
>         Karl

Hint:
    a='1  2'
    echo $a
    echo "$a"

-- 
William Park <opengeometry@yahoo.ca>
Linux solution for data processing. 
0
William
11/28/2004 6:31:55 AM
KKramsch <karlUNDERSCOREkramsch@yahooPERIODcom.invalid> wrote in message:

> 
> I just read in a book that to one way to find out the value of an
> enviroment variable is to give it as the argument to echo, preceded
> by a $ and surrounded by double quotes, as in echo "$FOO".  Why
> the quotes?  It seems that I get the same results whether I do echo
> $FOO or echo "$FOO".
> 

To avoid mangling the space/TABs/newlines in the variable name

AND

to avoid wildcard expansion incase FOO contains the file-globbing
chars like * ? [ etc.
0
sharma__r
11/28/2004 12:38:52 PM
2004-11-28, 06:24(+00), KKramsch:
> I just read in a book that to one way to find out the value of an
> enviroment variable is to give it as the argument to echo, preceded
> by a $ and surrounded by double quotes, as in echo "$FOO".  Why
> the quotes?  It seems that I get the same results whether I do echo
> $FOO or echo "$FOO".
[...]

That's because of the special behavior of Bourne like shells
(not zsh unless in sh/ksh compatibility mode). When a variable
is left unquoted, word splitting occurs and filename generation
is done.

That means that if

var="1|*"

(and the internal field separator is "|" (IFS="|"))

in:

echo $var

echo is passed several arguments: "1" and the list of (non-dot)
filenames in the current directory.

zsh (and rc and es) have a more consistent behavior, however
note that (not for rc nore es that have a yet more consistent
behavior)

echo $var

and 

echo "$var"

are different in case $var is empty. In the first case, echo is
passed no argument. In the second, it is passed one empty one.

-- 
Stephane
0
Stephane
11/28/2004 1:15:04 PM

Thanks!

	Karl
-- 
Sent from a spam-bucket account; I check it once in a blue moon.  If
you still want to e-mail me, cut out the extension from my address,
and make the obvious substitutions on what's left.
0
KKramsch
11/28/2004 3:37:25 PM
Reply: