[Top][All Lists]

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

Re: i++ cause bad return code when result is 1

From: Linda Walsh
Subject: Re: i++ cause bad return code when result is 1
Date: Mon, 19 Aug 2013 20:23:41 -0700
User-agent: Thunderbird

David Lehmann wrote:

The ((i++)) fails only when the result is 1.
What are you calling the result?  The return value or
the post-incremented value of 'i', which is done *after* the
return-result is returned?

I.e. you are talking 2 different point of return (that's one
issue).  Second, others have answered and that is if you have
an integer 0, like

if ((0)) ; then (should this execute or not?)...

Since values in (()) are evaluated similarly to 'C',
and in 'C', 0 usually = false... then you end up with
arithmetic 0 = false = > failure case;

now if you use:
if [[ (0) ]]; then echo this is true;  fi

The wonders of shell (which make sense if you consider
why, but not entirely intuitive on a casual glance...)...

If you do computations in (()), be
save and " ((xxx))||: ", which looks ugly
after you do it a while... so you move
on and forget the (())
and use:

alias int=declare\ -i
int i=0
int j=i++
echo $j, $i, $?
  0 1 0
echo $j, $i, $?
  1 2 0
echo $j, $i, $?
  2 3 0
(or whatever, but the above always sets the exit code 0
so no errexit trigger)

reply via email to

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