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

Re: PATCH: octal in arithmetic expressions



> This should make zsh conform to POSIX in this regard.

i.e. $(( 010 )) is treated as 8.

We had this, but removed it because it messed up huge numbers of shell
scripts (including mine) with perfectly reasonable leading zeroes that
never did anyone any harm, and very few people needed octal, and there are
other, less ambiguous ways of specifying it.  Consider for example,

% print -P %D
00-05-15

If you extract bits of this as a string and then try to do math on it, it
falls other if the number is 08 or 09.  This is much more the sort of thing
most zsh users are likely to want to do rather than parsing octal.

It should be settable with some option such as
MATH_MODE_MESSES_UP_CONVERSIONS_FROM_STRING_TO_INTEGER... well, all right,
OCTAL_ZEROES.  As ksh doesn't do this it probably shouldn't be set for
ksh emulation.  Unfortunately there isn't a specific posix emulation mode;
there probably should be.  I suppose it would be OK to set it in sh
emulation, since only sh's trying to be posix-like would have math
evaluation.

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxxx>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070



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