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