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

2012-12-07 Thread Orlob Martin (EXT)
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





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

2012-12-07 Thread Pierre Gaston
On Fri, Dec 7, 2012 at 12:52 PM, Orlob Martin (EXT) <
extern.martin.or...@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
> -DHAVE_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.


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

2012-12-07 Thread DJ Mills
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.or...@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
> -DHAVE_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
>
>
>
>