2004-11-28, 06:24(+00), KKramsch:
Quote:> 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
That means that if
(and the internal field separator is "|" (IFS="|"))
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
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.