Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Can't call multi-arg math function from array subscript
- X-seq: zsh-workers 40928
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Can't call multi-arg math function from array subscript
- Date: Sun, 2 Apr 2017 11:51:56 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:to:subject:mime-version; bh=UHz/8qCrSVLX9AMZZwfyp/iH88A3230BfKLSAKvtjU8=; b=o/1cTGvNKhIOpa2EOpA1+wMeWbXwOIQTbDQx1cxEpvIvzJfqqopb7YNAzyW96HejUY Qwr3r2dFQz+orJWPXNuste0Q3VE78wjmgfoyEB68B7NTZlb7d0uuQ2OGAduvafHMu5FD RHEXDpszImRV94Pl70TBBtydmpmLq7gzaY9GcC7mHizQGoWP1iAxNHGIpkQgB/xVtdSn 3h3eX9QRP64I3KjCiBCKMNC2taDqu9kErCKhHniOLs4EGdu5PeCjHm/3vG2x3hA6XRid t6zppoBW/4lKZMAUBUegth4FP7+3Me+DK9mzA1qC4jy205yz8UBk1t6C3tg58RETykYW i67g==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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