[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Incorrect exit status of the Build-IN (( ))
From: |
DJ Mills |
Subject: |
Re: Incorrect exit status of the Build-IN (( )) |
Date: |
Fri, 7 Dec 2012 10:52:58 -0500 |
This is the expected behavior, and it's the same in any language with a
'++' syntax.
var++ is POST-incrementing, that means the '+1' happens AFTER the expansion.
If you want it to happen before, you need pre-incrementing. ++var.
On Fri, Dec 7, 2012 at 5:52 AM, Orlob Martin (EXT) <
extern.Martin.Orlob@esolutions.de> wrote:
> Configuration Information [Automatically generated, do not change]:
> Machine: x86_64
> OS: linux-gnu
> Compiler: gcc
> Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
> -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu'
> -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL
> -DH AVE_CONFIG_H -I. -I../bash -I../bash/include -I../bash/lib
> -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector --param=ssp-buffer-size=4
> -Wformat -Wformat-security -Werror=format-security -Wall
> uname output: Linux ESO0560-ubuntu 3.2.0-25-generic #40-Ubuntu SMP Wed May
> 23 20:30:51 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
> Machine Type: x86_64-pc-linux-gnu
>
> Bash Version: 4.2
> Patch Level: 24
> Release Status: release
>
> Description:
> PROBLEM: Exit status not correct, when count up from zero using
> Build-in (( ))
>
> EXAMPLE (enter each following line in Bash):
> a=0
> ((a++))
> echo $?
> echo $a
> ((a++))
> echo $?
> echo $a
> COMMENTS TO EXMAPLE:
> The first ((a++)) should perform 'a+1' --> '0+1' (correct
> operation)
> The first 'echo $?' returns '1' which is not correct, since
> following 'echo $a' returns '1' (result of adding 0+1) which is
> correct
>
>
>
>