help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] How to make variable set in () accessible outside?


From: Dan Douglas
Subject: Re: [Help-bash] How to make variable set in () accessible outside?
Date: Wed, 02 May 2012 23:12:32 -0500
User-agent: KMail/4.8.2 (Linux/3.3.4-pf; KDE/4.8.2; x86_64; ; )

On Wednesday, May 02, 2012 10:37:04 PM Peng Yu wrote:
> Hi,
> 
> (export XXX=a)
> echo $XXX
> 
> In the above code, the echo command will print nothing. I'm wondering
> if there is a way make the variable set in () accessible outside.

Any time there's a subshell involved, you're effectively dealing with a 
separate independent process with its own shell execution environment. There's 
no way to make anything inside directly accessible to the outside.  The only 
ways to interact with a subshell are the same as with any other external 
command - mostly that's via standard streams.

Lots of examples here: http://mywiki.wooledge.org/BashFAQ/002

Also remember that export is a POSIX special builtin, and Bash (thankfully, 
IMO) doesn't follow the spec on this by default.

 ~ $ ( bash -c 'xxx=a export a; echo "$xxx"' )

 ~ $ ( bash --posix -c 'xxx=a export a; echo "$xxx"' )
a

The above isn't related to a subshell issue.

Is there a specific problem you're trying to solve?
-- 
Dan Douglas

Attachment: signature.asc
Description: This is a digitally signed message part.


reply via email to

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