bug-bash
[Top][All Lists]
Advanced

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

Re: parent shell/sub-shell puzzlement


From: Paul Jarc
Subject: Re: parent shell/sub-shell puzzlement
Date: Wed, 05 Feb 2003 13:46:43 -0500
User-agent: Gnus/5.090015 (Oort Gnus v0.15) Emacs/21.2 (i686-pc-linux-gnu)

Ian Macdonald <address@hidden> wrote:
> while read one two three; do
>       four=fiz
>       echo In loop: $one $two $three $four
> done < <(echo foo bar baz)
> echo Outside loop: $one $two $three $four
>
> As far as I can see, $one, $two, $three and $four are defined at the
> same level. I would expect the while loop to print all four values on
> one line and the outer echo to print nothing.
...
> However -- and now I'm getting to the source of my puzzlement -- if the
> body of the while loop is, in fact, executed in the main shell, why are
> the values of $one, $two and $three not also set in the main shell?

The first time through the loop, read assigns the values foo, bar, and
baz to the variables one, two, and three.  The second time, read sees
EOF, so as described in the man page:
              If there are fewer words read from the input stream than
              names, the remaining names are assigned empty values.
In this case, 0 words are read from the input stream, so all the
variables are set to the empty string.  But there is nothing to reset
four.


paul




reply via email to

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