bug-bash
[Top][All Lists]
Advanced

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

Re: unexpected exit code for integer operation


From: Kerin Millar
Subject: Re: unexpected exit code for integer operation
Date: Wed, 27 Oct 2021 21:09:38 +0100

On Wed, 27 Oct 2021 21:09:29 +0200
Toralf Förster <toralf.foerster@gmx.de> wrote:

> Hi,
> 
> expected:
> $ i=0; ((i = i + 1)); echo $?
> 0
> 
> expected:
> $ i=0; ((++i)); echo $?
> 0

This makes use of a pre-increment operator. The evaluated number is 1.

> 
> unexpected:
> $ i=0; ((i++)); echo $?
> 1

This makes use of a post-increment operator. The evaluated number is 0.

> 
> i is always set to 0, the result is always non-zero, but the return code
> differs.

This is to be expected. It works the same way as in other languages, such as C. 
You should use the operator that reflects your intent.

-- 
Kerin Millar



reply via email to

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