[ale] Perplexed by bash

Joe Steele joe at madewell.com
Tue May 3 18:05:33 EDT 2005


The problem is the use of a pipe.  Each half of the pipe is run in a 
separate subshell.  Consequently, RC is set to "123" in a subshell, 
while the parent shell (which runs 'echo "RC: $RC"') only knows the 
original value (if any) of RC.

--Joe

On Tuesday, May 03, 2005 6:16 PM, John Wells wrote:
>
> Can anyone tell me why the while loop in the below code affects the
> setting of the variable RC?  I'm at a loss.  Remove the while loop, and it
> works just fine...
> --
> #!/bin/bash
> function getRC
> {
>   RC="123"
> }
>
> getRC \
> | while read line
> do
>   echo "456"
> done
>
> echo "RC: $RC"
>



More information about the Ale mailing list