bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: $((expr)) allows the hexadecimal constant "0x"


From: Koichi Murase
Subject: Re: $((expr)) allows the hexadecimal constant "0x"
Date: Tue, 12 Dec 2023 10:43:28 +0900

2023年12月10日(日) 15:58 Koichi Murase <myoga.murase@gmail.com>:
> 2023年12月10日(日) 14:13 Martin D Kealey <martin@kurahaupo.gen.nz>:
> > But even if you still thought this was worth doing, it wasn't necessary to
> > make $((10#)) completely illegal: Bash could look ahead and only intervene
> > if the following character is '-' (affecting $((10#-digits)) but not
> > $((10#))).
>
> I'm not a big fan of `10#[-+]digits' and invalidating `10#' either
> since the Bash change also broke mine [1,2], but I'd say the above
> lookahead switching is worse than the current behavior. [...]

I checked the behaviors of different shells because I was interested
in them.  They seem to vary more than I expected.

          | $((10#)) | $((2*10#-1)) | $((2*10#- 1))
----------|----------|--------------|---------------
bash-5.0  | 0        | -1           | -1
bash-5.1  | error    | error        | error
ksh93u    | 0        | -2           | -1
ksh93v    | error    | error        | error
mksh      | 0        | -1           | -1
zsh       | 0        | -2           | error

ksh93u is tested with "Version AJM 93u+m/1.0.3 2022-08-25" and
"Version AJM 93u+ 2012-08-01". ksh93v is tested with "Version A
2020.0.0" (strictly speaking, this is not 93v but developed based on
93v).  $((2*10# -1)) was the same as $((2*10#-1)). $((2*10# - 1)) was
the same as $((2*10#- 1)).

bash-5.0 behaves in the same way as mksh. bash-5.1 behaves in the same
way as ksh93v. ksh93u and zsh behave in a similar way, but zsh
produces a syntax error with `10#- 1'.  I think the behavior of zsh is
similar to the lookahead switching suggested by Martin.  ksh93u also
performs a kind of lookahead switching, but it's different from what
Martin suggests.

I guess bash-5.1 referenced the behavior of ksh93v, but this is
actually not an actively maintained branch.  Recently, ksh under an
active development seems to be ksh93u+m derived from ksh93u+.

--
Koichi



reply via email to

[Prev in Thread] Current Thread [Next in Thread]