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


Groups > gnu.bash.bug > #16825

Re: Incrementing variable=0 with arithmetic expansion causes Return code = 1

From "" <kfm@plushkava.net>
Newsgroups gnu.bash.bug
Subject Re: Incrementing variable=0 with arithmetic expansion causes Return code = 1
Date 2020-08-28 14:09 +0100
Message-ID <mailman.1595.1598620153.2469.bug-bash@gnu.org> (permalink)
References <GVAP278MB0118201C70D7FAF7B4DF612D98520@GVAP278MB0118.CHEP278.PROD.OUTLOOK.COM> <8c456f29-8e0d-e0bc-4645-c7cc5b6c6471@plushkava.net>

Show all headers | View raw


On 28/08/2020 09:00, Gabriel Winkler wrote:
> Configuration Information [Automatically generated, do not change]:
> Machine: x86_64
> OS: linux-gnu
> Compiler: gcc -I/home/abuild/rpmbuild/BUILD/bash-4.4 -L/home/abuild/rpmbuild/BUILD/bash-4.4/../readline-7.0
> Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-suse-linux-gnu' -DCONF_VENDOR='suse' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib   -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -g  -D_GNU_SOURCE -DRECYCLES_PIDS -Wall -g -Wuninitialized -Wextra -Wno-switch-enum -Wno-unused-variable -Wno-unused-parameter -Wno-parentheses -ftree-loop-linear -pipe -DBNC382214=0 -DIMPORT_FUNCTIONS_DEF=0 -fprofile-use -fprofile-correction
> uname output: Linux sophie 4.12.14-150.32-default #1 SMP Thu Aug 1 08:42:52 UTC 2019 (a2a3983) x86_64 x86_64 x86_64 GNU/Linux
> Machine Type: x86_64-suse-linux-gnu
> 
> Bash Version: 4.4
> Patch Level: 23
> Release Status: release
> 
> Description:
> If I have a variable with the value 0 assigned to it incrementing it causes the return code to be 1, even though the variable has been incremented successfully. This only happens if the value of the variable is 0. With positive and negative values this bug is no present.
> 
> Repeat-By:
> # Works fine
> test=1
> ((test++))
> echo $?
> 0
> echo $test
> 2
> 
> # Causes error
> test=0
> ((test++))
> echo $?
> 1
> echo $test
> 1

This isn't a bug. You should write ((++test)) if you want the 
post-incremented value to be evaluated.

-- 
Kerin Millar

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


Thread

Re: Incrementing variable=0 with arithmetic expansion causes Return code = 1 "" <kfm@plushkava.net> - 2020-08-28 14:09 +0100

csiph-web