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

Re: A bug or improperly formatted script



On Feb 25,  4:53pm, Jim wrote:
}
} So in my original email the alternate example
} 
}  print $((${(z)${(fO)"$(dirs -v)"}[1][1]} + 1))
} 
} was this forcing it to an array or was it a fluke?

It was a fluke.  ${${$(print $'0\t~')[1]}[1]} == '0' whereas
${${$(print $'0\t~')[-1]}[1]} == '~' and $(( ~ + 1 )) == -2 (the
tilde being interpreted as bitwise negation).

Double-subscripting $var[1][1] yields the same byte whether $var is
a scalar or an array, whereas $var[-1][1] does not unless the scalar
is only a single character to begin with.

You'd never have seen -2 if $HOME were not the only entry in the
stack.  With $(dirs -lv) or with most other directories, the last char
of the directory name would have been intepreted as a variable name
and potentially produced even stranger results (though most like it
would be an unset variable and thus be treated as zero, hiding the
effect entirely).  A directory name ending in digits would have made
things even stranger.



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