bug-bash
[Top][All Lists]
Advanced

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

Re: Incorrect exit status of the Build-IN (( ))


From: Pierre Gaston
Subject: Re: Incorrect exit status of the Build-IN (( ))
Date: Fri, 7 Dec 2012 13:35:30 +0200

On Fri, Dec 7, 2012 at 12:52 PM, 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
>

Not a bug, a++ adds one to "a" but the result of the expression is the
value of a before the increment, so it's 0.
you can see it using echo $((a++)) instead of ((a++))

((++a)) does what you expect.


reply via email to

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