bug-bash
[Top][All Lists]
Advanced

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

Re: math operations with base#prefix


From: Kerin Millar
Subject: Re: math operations with base#prefix
Date: Tue, 19 Sep 2023 09:52:21 +0100
User-agent: Cyrus-JMAP/3.9.0-alpha0-761-gece9e40c48-fm-20230913.001-gece9e40c

On Tue, 19 Sep 2023, at 8:40 AM, Victor Pasko wrote:
> Thanks for your response.
> In my opinion, in let "<>" and $((<>)) constructs all variables should be
> evaluated, so that $-sign for them is to be  just optional

You haven't thought this through. It would amount to an egregious break of 
backward compatibility, even by the standards of bash. How would you expect for 
digits above 9 to be expressed for bases above 10?

You might, perhaps, argue that the n in "base#n" could be quoted.

$ ff='fe'
$ echo $(( 16#ff ))   # imaginarily prints 254 (instead of 255)
$ echo $(( 16#'ff' )) # imaginarily prints 255 (instead of being an error of 
syntax)

Keep in mind that this would render bash less consistent - and harder to reason 
with - than it already is. For example, $(( 'ff' )) is already an error of 
syntax in the Shell Command Language. Not to mention that it would further 
distance bash from other shells, such as ksh93 and zsh.

Additionally, you imply that let and $(( should be treated specially. At least, 
it seems that way because you speak of those two arithmetic contexts, yet not 
of the others [1]. Why?

[1] ((, for, array subscripts, string-slicing parameter expansions etc

-- 
Kerin Millar <kfm@plushkava.net>



reply via email to

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