[ale] Perplexed by bash

John Wells jb at sourceillustrated.com
Tue May 3 21:09:42 EDT 2005


Joe Steele said:
> 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.

ahhh...ok.  I wasn't aware that a pipe caused _both_ sides to be run in a
subshell.

To answer the question about what we're trying to do...we have a function
which starts a number of server processes.  We want to take the standard
out and error from this function call and, in realtime as new output is
available,  pass it to another function that handles logging.  So, in the
real script, you have something like:

start_processes 2>&1 | while read line
do
 log_message $line
done

This works just fine, but the final requuirement is to capture the return
value of the start_processes call.  Obviously, it's too late after the
loop, so my intent was to have the function set the RC variable to its
return value...evidently not thr right approach either.

Any suggestions?

Thanks, as always, for the help!

John



More information about the Ale mailing list