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: Pierre Gaston
Subject: Re: [Help-bash] Is it reasonable to let zero numeric value results in non zero exit status?
Date: Mon, 22 Oct 2018 08:55:13 +0300

On Mon, Oct 22, 2018 at 5:30 AM Peng Yu <address@hidden> wrote:

> 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.
>

I'm not sure if having a special case for this is a good idea.
It follows the C syntax and like in C the assignment has the value of the
of the variable after the assignment.
For what it's worth some think that it is not a good idea and error prone
e.g. python doesn't allow this.

Moreover, other assignments in bash can exit with non 0 eg:
x=$(false);echo $?

I personally prefer using: x=$(( )) rather than ((x=)), I find it more
natural and it doesn't exit with 1.


reply via email to

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