bug-bash
[Top][All Lists]
Advanced

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

Re: retrun value of buildin (( )) / GNU bash, version 4.2.24(1)-release


From: Roman Rakus
Subject: Re: retrun value of buildin (( )) / GNU bash, version 4.2.24(1)-release (x86_64-pc-linux-gnu)
Date: Tue, 10 Jul 2012 18:57:01 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120329 Thunderbird/11.0.1

On 07/10/2012 05:32 PM, Orlob Martin (EXT) wrote:
Hallo,

I was using the build in (( )) function for  count up an index. I think I found 
a bug in GNU bash, version 4.2.24(1)-release (x86_64-pc-linux-gnu).
((expression)) is one of Compound Commands (not builtin nor function).
Quoting the manual page:
((expression))
The expression is evaluated according to the rules described
below under ARITHMETIC EVALUATION. If the value of the expres‐
sion is non-zero, the return status is 0; otherwise the return
status is 1. This is exactly equivalent to let "expression".

See also a comment below inline.

The (( )) function is working fine, but the corresponding return value does not 
match.
  Check following small example (have the focus on $?)

----------SCRIPT START-----------------
#!/bin/bash

index=-3
for a in 1 2 3 4 5 6 7  ; do
         echo "Index before: $index"
         (( index++ ))
       echo "Return value: $?"
       echo "Index after: $index"
       echo "----"
done
----------SCRIPT END------------------

OUTPUT is:


Index before: -3
Return value: 0
Index after: -2
----
Index before: -2
Return value: 0
Index after: -1
----
Index before: -1
Return value: 0
Index after: 0
----
Index before: 0
Return value: 1<-- ?BUG? The index was counted up correctly, from 0 to 1, but return 
value of (( ))-function is "1"
No, works like intended. index value is 0 (zero) and thus return value of (( )) is 1. And the value of index is post-incremented.
Index after: 1
----
Index before: 1
Return value: 0
Index after: 2
----
Index before: 2
Return value: 0
Index after: 3
----
Index before: 3
Return value: 0
Index after: 4


Cheers,

Martin







----------------------------------------------------------
Martin Orlob - Systemintegrator

Im Auftrag der
e.solutions GmbH
GVZ Halle N West / Eingang A,
Pascalstraße 5, 85057 Ingolstadt, Germany

Registered Office:
Pascalstr. 5, 85057 Ingolstadt, Germany

Phone +49-8458-3332-702
Fax +49-8458-3332-20130
mailto: 
extern.Martin.Orlob@esolutions.de<mailto:extern.Martin.Orlob@esolutions.de>

e.solutions GmbH
Managing Directors Uwe Reder, Dr. Riclef Schmidt-Clausen
Register Court Ingolstadt HRB 5221





reply via email to

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