bug-bash
[Top][All Lists]
Advanced

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

Re: possibly incorrect handling with echo | read


From: Ian Macdonald
Subject: Re: possibly incorrect handling with echo | read
Date: Mon, 9 Dec 2002 09:09:40 -0800
User-agent: Mutt/1.4i

On Mon 09 Dec 2002 at 09:07:25 +0100, you wrote:

> Description:
>         I'm not sure if this is a bug or (un)documented feature, but I
>       did note a difference in behaviour compared with ksh (on
>       HP-UX).

Most other shells that copy Bourne syntax work the ksh way, although
interestingly, pdksh works the Bourne way.

>         In the following script line var1 and var2 will not get the
>       values:
> 
>                 echo "value1 value2" | read var1 var2
> 
>         In the following script lines var 1 and var2 will get the
>       values:
> 
>                 echo "value1 value2" | while read var1 var2
>                 do
>                         :
>                 done

In fact, these two code examples are comparing different things.

In the first, you echo two values into a subshell, set them as
variables in the subshell, and then later attempt to display their
values in the parent shell. This fails, because setting them in the
subshell does not affect the environment of the parent.

In the second, you display the value of the variables in the
*subshell*, where they *are* still set.

If you try to display the value of the variables after the while loop
instead of inside it, you'll find that the variables are also
unaffected in the parent shell of the second example.

Ian
-- 
Ian Macdonald               | Immanuel Kant but Kubla Khan. 
address@hidden             | 
                            | 
                            | 
                            | 



reply via email to

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