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

Subscript of negatively-subscripted array element gives incorrect result



Hi,

I reported this previously through the Bugs section on the Sourceforge page 
for zsh, but wasn't sure if it was active.  I also have a bit more 
information.

I am getting different results taking a substring of the same array element 
when I index it negatively than when I index it positively.  Here is an 
example:

These are correct:

% t=(foo bar baz)
% print ${t[2]}
bar
% print ${${t[2]}[1]}
b
% print ${${t[2]}[1,2]}
ba
% print ${${t[2]}[2]}
a
% print ${${t[2]}[2,3]}
ar
%

This is also correct:

% print ${t[-2]}
bar

These are not correct:

% print ${${t[-2]}[1]}
bar
% print ${${t[-2]}[1,2]}
bar
% print ${${t[-2]}[2]}

% print ${${t[-2]}[2,3]}

%

Those last 2 yield an empty string.

I verified this behavior with 4.0.4, 4.0.9, 4.1.1 and 4.2.0 on a Debian 
GNU/Linux system.

Thanks!

-Jonathan Hankins



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