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, i.e. subshell=sub process, but aside from 'symantic' issues, I didn't really say fully what I meant -- you would have to read it in context of the previous message where the idea was to 'set' the global vars in the subshell (not in a complex statement) (ex. A, below) OR be able use a complex statement in place of a subshell after "<<<" (ex. B, below)
Pierre Gaston wrote: > On Mon, Jul 25, 2011 at 8:33 PM, Linda Walsh <b...@tlinx.org> wrote: >> Pierre Gaston wrote: >>> Since you are already using global variables, why not simply use a >>> couple more for the return values? >>> >> --- >> Because a subshell cannot access the global variables of the >> parent. > > uh? you don't make sense. > 1) a subshell can access the parent variables just fine > 2) your intial problem was to avoid the subshell of your solution to > be able to use global variables > > I'm just saying : foo () { ret1=blah;ret2=bleh; }; foo;echo $ret1 $ret2 > ---- Arg:... I'm hard to interpret, but, but that's cuz, gaston, ya got me confused and off track, and I responded to what you said within the context of what I was trying to do (set global variables in the function that also returned values). I had originally: A) read var1 var2 var3 <<<$(function a b c); (where what I mean was function was the name of some random function, which I would hope could be gathered from syntax) What I wished for was B) read var1 var var3 <<<${func a b c} where I not only could have func pass back explicit return values, but also, operate in the context of the parent, thus being able to affect the parent's env vars. The first form is the only form that works AFAIK, the 2nd form is what I want to do ... ---- gaston replied: Since you are already using global variables, why not simply use a couple more for the return values? --- Ok, here's where things got confusing. I gave A & B and you responded with something that fell out of my example paradigm -- a function returning explicit values, but also being able to effect the global ENV. So I, first thing in the morning, I thought you were thought you were asking "why not have $(function a b c) just return vals in 'global variables'"? (which, I understand now, isn't what you meant). That's why I responded that the subshell can't access [for purposes of SETTING (*context*)), global vars... So...now that that's all explained. there's still the original want... (am still experimenting w/the 'pass-by-value stuff that DJMills referred to, trying to flesh out a few more odd cases..., so of course I end up writing a program to handle it all (got to complex doing all in interactively). will keep you posted if you are interested...