Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

xtrace and array assignment



The trace output for assignment to array elements does not expand the
index value (the string inside the square brackets):

schaefer<512> {
cursh> typeset -A traceme
cursh> theindex=somestring
cursh> set -x
cursh> traceme[$theindex]=$theindex
cursh> set +x
cursh> }
: zsh:19:cursh; traceme[$theindex]=somestring 
: zsh:20:cursh; set +x
schaefer<513> 

I'm a little conflicted about this one because (a) the above behavior
matches bash and (b) sometimes seeing it unexpanded is what you want.
On the other hand, if I'm tracing a function with "typeset -ft" and
the assignment looks like thearray[$2]=thevalue, it'd be helpful to see
what $2 is, because the trace does not include the function call itself
from the surrounding context.

Yes, that specific example can be worked around by adding something such
as ": $@" to the top of the function, but there may be other contexts
where it's difficult follow where a reference came from, and the intent
of typeset -ft is to avoid having to change the function.

It's also always irked me a little that the verbose option doesn't print
anything for assignments, so maybe combining verbose and xtrace could
have some meaning here.  However, I haven't really dug in to how xtrace
for assignments is implemented, so this might be rather difficult, and
of course we don't want to accidentally introduce side-effects.



Messages sorted by: Reverse Date, Date, Thread, Author