Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Airthmetic confusion...

On May 17,  5:13am, Meino Christian Cramer wrote:
}  I see that "0" is false and !0 is true...but...we
}  are doing arithmetic and not logical evaluation.

No, that's not true.

First of all, the closest thing to "logical" evaluation that the
shell does is the &&, ||, etc., subexpressions WITHIN arithmetic
expressions.  The && and || constructs that test process success
or failure are NOT "logical" operators -- for one thing, they do
not obey the usual Boolean precedence rules.  "set -e" is not a
"logical" comparison by any stretch.

Second, when you write (( expression )) then you are explicitly
instructing the shell to do BOTH arithmetic evaluation AND shell
expression success/failure.  That's what the double parens MEAN,
when not preceded by a dollar sign.

If you want ONLY arithmetic evaluation, use $(( expression )),
and apply the colon command if necessary, e.g.

    : $(( x = a - b ))


    x=$(( a - b ))

Those are both successful shell expressions that result in zero-
value assignments to x.

As with any other programming language, you have to write exactly
what you mean, and you have to follow the language's semantic rules,
not the rules as you think they should be.

}  As a sideffect a previously existant variable become inexistant by
}  assigning a "0"?

What makes you believe that's happening?  Assignments can only create
variables, they can't unset them.

Messages sorted by: Reverse Date, Date, Thread, Author