help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Simple echo is printing the wrong value


From: Chet Ramey
Subject: Re: [Help-bash] Simple echo is printing the wrong value
Date: Thu, 05 Apr 2012 11:35:40 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2

On 4/4/12 11:24 PM, Bill Gradwohl wrote:

> It's the difference I was trying to highlight and figure out why * does
> different things under different circumstances.
> 
> Greg called it magic. To me it's just confusing. Expanding * in the case
> construct doesn't make sense, I agree, but I would issue an error message
> instead. If * expands in one context, it should expand in all contexts, and
> in those where it doesn't make sense, do the equivalent of a compile error,
> bad substitution, whatever.

OK, but that ship sailed thirty years ago.  It's not going to change, and
discussing it is tilting at windmills.

In one sense the set of expansions each shell construct undergoes is
inconsistent, because what happens to the word following `case' is not
the same as what happens to an argument to `echo' is not the same as
what happens to a word following a redirection operator is not the same
as what happens to a line in the body of a here-document.  But this is
partly a function of what makes sense for each construct in the largest
number of cases and partly history.

You might be interested in looking at the Plan 9-inspired `rc' shell,
which behaves in a radically different way where word splitting is
concerned.

> That's what makes sense to me. I realize that's impossible with bash at
> this late stage of the game with people relying on how it functions as is,
> but its these idiosyncrasies that I keep bumping in to.
> 
> IFS= read                works
> 
> set -- '' '' ''
> IFS= echo "${*}"         doesn't
> 
> Yes - I know its a parser issue, but its still unexpected.

It's not a parser issue.  (In my best Arnold voice from "Kindergarten Cop":
"It's not. At all.") It's an issue of understanding how the commands work.
echo and read each get arguments expanded the same way.  read uses IFS as
part of its internal processing; echo does not.  This has nothing to do
with lexical analysis, parsing, or word expansion.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]