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

Can't call multi-arg math function from array subscript



Single-argument functions are OK:

% string='abcde'
% onearg() { return $1 }
% functions -M onearg
% print ${string[1,onearg(3)]
abc

Add another argument and strange things start happening:

% twoarg() { return $(( $2 - $1 )) }
% functions -M twoarg
% print ${string[1,twoarg(1,4)]}
twoarg: bad math expression: operand expected at end of string
twoarg: bad math expression: operand expected at end of string

Why two error messages?

I assume the comma is messing things up; let's try it like this:

% print ${string[1,$(( twoarg(1,4) ))]}
zsh: parse error
zsh: parse error

Just to confirm:

% print ${string[1,$(( onearg(4) ))]} 
abcd



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