zsh-workers
 help / color / mirror / code / Atom feed
* Arith parsing bug with minus after $#
@ 2015-05-28 19:42 Martijn Dekker
  2015-05-29 15:02 ` Peter Stephenson
  0 siblings, 1 reply; 12+ messages in thread
From: Martijn Dekker @ 2015-05-28 19:42 UTC (permalink / raw)
  To: zsh-workers

After the getopts patch (which appeared within an hour after my report
-- impressive!), I ran into another hurdle with the same shell function.
Doing arithmetic calculations with the shell parameter containing the
number of positional parameters ($#) triggers a parsing bug in
arithmetic evaluation.

In current zsh git code:

$ zsh
% set --
% echo $#
0
% echo $(($#-1))
41

Expected output: -1, of course. Sometimes 81 is produced instead of 41!
I haven't figured out a pattern yet.

% echo $(($#-(1+1)))
zsh: bad math expression: operator expected at `(1+1)'

(expected output: -2)

In both cases, it does work correctly if a space is inserted before the
'-', but that space should be optional.

Enabling 'emulate sh' makes no difference.

This must be a long-standing bug, becasue zsh 4.3.11 that came with my
Mac has it too.

(According to my testing, other shells that support arith all do this
correctly.)

- Martijn


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2015-06-07  1:14 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-28 19:42 Arith parsing bug with minus after $# Martijn Dekker
2015-05-29 15:02 ` Peter Stephenson
2015-05-29 15:43   ` Martijn Dekker
2015-05-29 18:09   ` Bart Schaefer
2015-05-29 19:33     ` Martijn Dekker
2015-05-29 20:48       ` ZyX
2015-05-29 21:24         ` Bart Schaefer
2015-05-30 19:24           ` Peter Stephenson
2015-05-30 19:40             ` Peter Stephenson
2015-05-30 22:28               ` Bart Schaefer
2015-05-30 23:30                 ` Peter Stephenson
2015-06-07  1:08   ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).