Dan,

This behaviour looks correct to me; all but the right-most part of a pipeline will get processed in a subshell, and do not share any data
with the parent process.

The assignment is never executed in the parent, and so the array
remains empty.

Cheers,

Henk



On 2010-03-19 01:05, [email protected]:
AST-Users,

I had written a function essentially like "loadTheArrayVer2" below. In the 
calling code, after calling the function, my array was dead empty. To my way of thinking, 
this behavior is most unexpected, If this is proper, then please help me understand the 
logic behind it, so that I don't make the same mistake again.

$ cat kshScopeIssue
function loadTheArrayVer1
{
nameref array_ref=$1
print | for i in justOnce; do array_ref[ jdoe ]='John Doe'; done
}
function loadTheArrayVer2
{
nameref array_ref=$1
print | for i in justOnce; do array_ref[jdoe]=' John Doe '; done | while read; 
do :; done
}
function loadTheArrayVer3
{
nameref array_ref=$1
for i in justOnce; do array_ref[ jdoe ]=' John Doe '; done | while read; do :; 
done
}
print ${.sh.version}
#--- The following three groups (4 lines each) differ only by the numeric 
character at the end of the function names.
unset array
typeset -A array
loadTheArrayVer1 array
print "Using loadTheArrayVer1: ${arr...@]}"

unset array
typeset -A array
loadTheArrayVer2 array
print "Using loadTheArrayVer2: ${arr...@]}"

unset array
typeset -A array
loadTheArrayVer3 array
print "Using loadTheArrayVer3: ${arr...@]}"


$ ./kshScopeIssue
Version JM 93t+ 2010-02-02
Using loadTheArrayVer1: John Doe
Using loadTheArrayVer2:
Using loadTheArrayVer3:


Thanks,
Dan




_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to