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 <wool...@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).