On 5/3/14, 10:59 PM, Linda Walsh wrote: > > > Arfrever Frehtes Taifersar Arahesis wrote: >> bash 4.2.47: >> $ export VAR1=abc VAR2=abc >> $ f() { local VAR1; local -x VAR2; bash -c 'declare -p VAR{1,2}'; } >> $ f >> bash: line 0: declare: VAR1: not found >> bash: line 0: declare: VAR2: not found >> >> bash 4.3.11: >> $ export VAR1=abc VAR2=abc >> $ f() { local VAR1; local -x VAR2; bash -c 'declare -p VAR{1,2}'; } >> $ f >> declare -x VAR1="abc" >> declare -x VAR2="abc" > --- > What's especially peculiar is that if you change VAR1+VAR2 > in 'f', then the called bash in 'f' should still see the original > value of VAR1 as it was not exported (but it sees both > values as assigned in 'f'.
Yes. Once you assign a value to the local instances of the variables, they are set. Local variables inherit the exported status of the variable they are shadowing to avoid surprises in the export environment. Believe it or not, it's less surprising than letting a local variable shadow a global for everything except exporting to child processes. It's been that way forever (well, at least as far back as bash-2.05b, when I quit looking.) Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/