bug-bash
[Top][All Lists]
Advanced

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

Re: ((i++)) no longer supported?


From: Chris F.A. Johnson
Subject: Re: ((i++)) no longer supported?
Date: Thu, 3 May 2012 14:21:42 -0400 (EDT)
User-agent: Alpine 2.00 (LMD 1167 2008-08-23)

On Thu, 3 May 2012, DJ Mills wrote:

On Thu, May 3, 2012 at 2:53 AM, Pierre Gaston <pierre.gaston@gmail.com> wrote:
On Thu, May 3, 2012 at 9:34 AM, Pan ruochen <panruochen@gmail.com> wrote:
Hi All,

Suddenly I found that ((i++)) is not supported on bash.
Just try the following simple case:
$i=0; ((i++)); echo $?
And the result is
1
which means an error.
I got the same result on GNU bash, version 4.1.2(1)-release
(x86_64-redhat-linux-gnu) and GNU bash, version 4.1.10(4)-release
(i686-pc-cygwin).

- BR, Ruochen


It has always been the case, and fits the documentation since i++
value is 0 and that is false in the arithmetic context.

What changed is that it bash exits in this case if you use set -e.
Some Possible workarounds:
((i++)) || :
((i+=1))
i=$((i+1))
and a gazillon others.


The most sane workaround would probably be to stop using set -e.

   Better still, use the POSIX standard method shown above: i=$((i+1))

--
   Chris F.A. Johnson, <http://cfajohnson.com/>
   Author:
   Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)



reply via email to

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