NetBSD-Users archive

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

Re: /bin/sh question



Paul Goyette <paul%whooppee.com@localhost> wrote:

> Just out of curiousity, is there a reason why the following does not 
> work?  It generates "Symbol =" as output...
> 
>        #! /bin/sh
> 
>        echo "value" |
>          read symbol
>        echo "Symbol = $symbol"
> 
> Yet it does work if you do it as follows, generating the expected output 
> "Symbol = value"
> 
>        #! /bin/sh
>        echo "value" |
>        ( read symbol
>          echo "Symbol = $symbol" )

I think it is covered in usenet faq for shell programming.  The result
depends on which way your shell forks pipelines.

Some shells fork it from left to right, so to say, in which case the
first (leftmost) command is in the original shell process.  In that
case the "read" is in another sub-processes and changes made in that
sub-process do not affect the original shell process.

There are shells (I don't remember which) that fork pipelines
backward, in that case the last (righmost) command is in the original
shell process and your example will print "value" for $symbol.

-uwe



Home | Main Index | Thread Index | Old Index