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).
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"
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.or...@esolutions.de<mailto:extern.martin.or...@esolutions.de>

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

Reply via email to