bug-bash
[Top][All Lists]
Advanced

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

Re: variable assignment in string returning function


From: Greg Wooledge
Subject: Re: variable assignment in string returning function
Date: Wed, 27 Jan 2010 08:16:32 -0500
User-agent: Mutt/1.4.2.3i

On Wed, Jan 27, 2010 at 03:07:40PM +0200, Pierre Gaston wrote:
> On Wed, Jan 27, 2010 at 2:49 PM, Sharuzzaman Ahmat Raslan
> <sharuzzaman@gmail.com> wrote:
> > Somehow, the backtick for foo() execute the function, echoing the correct
> > output, but fails to set the variable $gang to the correct value. Because of
> > that, the function bar() did not echoing anything because the variable $gang
> > is null.
> 
> `` and $() introduce subshells. The parent shell cannot be modified by
> the subshells.

For hints on working around this, see http://mywiki.wooledge.org/BashFAQ/084

The bad news is that it's pretty much impossible to capture stdout from
a function *and* set global variables at the same time.  You need to
choose one or the other, or use some file system object to store output.




reply via email to

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