bug-bash
[Top][All Lists]
Advanced

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

Re: strange result loop exit status


From: Dmitry Arkhireev
Subject: Re: strange result loop exit status
Date: Wed, 19 Mar 2014 19:10:33 +0400

Thank you, Greg.
It turned out I was wrong in the basics.
Your explanation made ​​me to review my code.
I will be more careful in the future.

19 марта 2014 г., в 18:27, Greg Wooledge <wooledg@eeg.ccf.org> написал(а):

> On Wed, Mar 19, 2014 at 02:18:52PM +0400, Dmitry Arkhireev wrote:
>> And if run it sample with echo $I after ((I++)) everything works as expected
>> I=0; while [ $I -ne 1 ]; do ((I++)); echo $I; done; echo $?
>> 1
>> 0
> 
> Here, $? is the exit status of the echo, instead of the ((...)) command.
> The ((...)) command returns a status of either 0 or 1, depending on the
> value of the expression it evaluates.
> 
> With C-style post-increment (++) the expression evalutes to the original
> value of the variable, rather than the incremented value.
> 
> imadev:~$ i=0; ((i++)); echo $?
> 1
> imadev:~$ i=1; ((i++)); echo $?
> 0
> imadev:~$ i=999; ((i++)); echo $?
> 0
> 
> When the original value is 0, the expression evaluates to "false"
> (using the semantics of C), and "false" causes an exit status of 1
> (using the semantics of Bash).  When the original value is anything
> other than 0, the expression evaluates to "true" (C-style), which
> causes an exit status of 0 (Bash-style).




reply via email to

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