Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15050

Re: Arithmetic evaluation of negative numbers with base prefix

From Ilkka Virta <itvirta@iki.fi>
Newsgroups gnu.bash.bug
Subject Re: Arithmetic evaluation of negative numbers with base prefix
Date 2019-06-14 21:30 +0300
Message-ID <mailman.93.1560537058.10840.bug-bash@gnu.org> (permalink)
References <20190614141947.GB27242@tower> <a1c88a1c-7127-4df1-f709-dd247c955064@iki.fi>

Show all headers | View raw


On 14.6. 17:19, Jeremy Townshend wrote:
> 	echo $((10#-1))   # -1 as expected

Earlier discussion about the same on bug-bash:
https://lists.gnu.org/archive/html/bug-bash/2018-07/msg00015.html

Bash doesn't support the minus (or plus) sign following the 10#.
I think the expression above seems to work in this case because 10# is 
treated as a constant number by itself (with a value of 0), and then the 
1 is subtracted.

try also e.g.:

   $ echo $((10#))
   0

> 	echo $((0-10#-1)) # -1 UNEXPECTED. Would expect 1.

So this is 0-0-1 = -1

-- 
Ilkka Virta / itvirta@iki.fi

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: Arithmetic evaluation of negative numbers with base prefix Ilkka Virta <itvirta@iki.fi> - 2019-06-14 21:30 +0300

csiph-web