[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to do? Possible?
From: |
Linda Walsh |
Subject: |
Re: How to do? Possible? |
Date: |
Mon, 25 Jul 2011 14:28:52 -0700 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.24) Gecko/20100228 Thunderbird/2.0.0.24 Mnenhy/0.7.6.666 |
Bob Proulx wrote:
> Linda Walsh wrote:
>> DJ Mills wrote:
>>>> Because a subshell cannot access the global variables of the parent.
>>> A subshell can access its parent's variables. foo=bar; ( echo "$foo" )
>>>
>>> A sub process cannot, unless the variables are exported. It does
>>> not sound like you need to do so here.
>> I'm not sure about your terminology -- a subshell is a
>> subprocess. By my understanding, "{}" defines a complex statement
>> and "()" defines both a subshell which is in a separate process,
>
> Yes, but it is a fork(2) of the parent shell and all of the variables
> from the parent are copied along with the fork into the child process
> and that includes non-exported variables. Normally you would expect
> that a subprocess wouldn't have access to parent shell variables
> unless they were exported. But with a subshell a copy of all
> variables are available.
>
> Bob
--
Not really.
It only seems that way because within () any "$xxxx" is usually
expanded BEFORE the () starts from the parent....
You can see this by
GLOBAL="hi there"
(echo $GLOBAL)
prints out "hi there" as expected, but if we hide
$GLOBAL so it isn't seen by parent:
(foo=GLOBAL; echo ${!foo})
prints ""
So, they aren't really available in a subshell, only
that a subshell's contents are evaluated before the subshell is
called.
- How to do? Possible?, Linda Walsh, 2011/07/25
- Re: How to do? Possible?, Pierre Gaston, 2011/07/25
- Re: How to do? Possible?, Linda Walsh, 2011/07/25
- Re: How to do? Possible?, DJ Mills, 2011/07/25
- Re: How to do? Possible?, Linda Walsh, 2011/07/25
- Re: How to do? Possible?, Bob Proulx, 2011/07/25
- Re: How to do? Possible?,
Linda Walsh <=
- Re: How to do? Possible?, Linda Walsh, 2011/07/25
- Re: How to do? Possible?, Eric Blake, 2011/07/25
- Re: How to do? Possible?, Linda Walsh, 2011/07/25
- Re: How to do? Possible?, Bob Proulx, 2011/07/25
- Re: How to do? Possible?, Dennis Williamson, 2011/07/25
- Re: How to do? Possible?, Bob Proulx, 2011/07/25
- Re: How to do? Possible?, Dennis Williamson, 2011/07/26
- Re: How to do? Possible?, Davide Brini, 2011/07/25
- Re: How to do? Possible?, Pierre Gaston, 2011/07/25
Re: How to do? Possible?, Steven W. Orr, 2011/07/25