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: Peng Yu
Subject: Re: [Help-bash] How to make variable set in () accessible outside?
Date: Wed, 2 May 2012 23:21:03 -0500

On Wed, May 2, 2012 at 11:12 PM, Dan Douglas <address@hidden> wrote:
> 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?

I need pass something computed in () to the enclosing environment. The
walkaround that I found was to use a tempfile.

-- 
Regards,
Peng



reply via email to

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