help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Is it reasonable to let zero numeric value results in no


From: Peng Yu
Subject: Re: [Help-bash] Is it reasonable to let zero numeric value results in non zero exit status?
Date: Sun, 21 Oct 2018 21:30:08 -0500

I think that there is a mix of two purposes 1) just using the
numerical values, 2) conditional testing. They should not be mixed up.

For the case of ((a > b)), it is obviously a testing. Then it makes
sense to return 1.

But for ((i--)) or ((x)), it is only the numerical values that matter.

In the context of while ((i--)) and ((x)) && echo hi, they can be
written as while ((i--==0)) and ((x==0)) && echo hi to make elimintate
the ambiguity.


On 10/21/18, Eduardo A. Bustamante López <address@hidden> wrote:
> On Sun, Oct 21, 2018 at 04:18:31PM -0500, Peng Yu wrote:
> (...)
>> I am not sure whether it is a good idea to return non zero exit status
>> when a numeric variable is zero, as this can cause problems when `set
>> -e` is used. Is there is a strong justification why this behavior is
>> reasonable?
>
> I understand what you're saying. I do have to ask though, how else would
> these examples work?
>
>     if ((a > b)); then
>      ...
>     fi
>
>     while ((i--)); do
>      ...
>     done
>
>     ((x)) && echo hi
>
>
> What rule would you use to know when to discard the return code?
>


-- 
Regards,
Peng



reply via email to

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