bug-bash
[Top][All Lists]
Advanced

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

Re: read output of process into a variable


From: Bob Proulx
Subject: Re: read output of process into a variable
Date: Wed, 30 Jan 2008 13:44:47 -0700
User-agent: Mutt/1.5.13 (2006-08-11)

Stefan Palme wrote:
> don't know if this is the right newsgroup, but it's the only one
> I can find with "bash" in its name :-)

That newsgroup is gatewayed to the bug-bash mailing list.

> I want to do something like this:
> 
>   result=""
>   /usr/bin/output_generator | while read line; do
>     extracteddata=`echo "$line" | sed -e 's/X/Y/'`
>     result="$result $extracteddata"
>   done
>   /usr/bin/another_tool "$result"
> 
> In the last line is "result" as empty as at the start of the
> whole thing - I guess because the inner "while" loop is executed
> in a subshell, so that changing the value of "result" in this
> loop does not affect the "outer result".

Please See the Bash FAQ question E4 for more information describing
this problem.

Bob




reply via email to

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