Zsh Mailing List Archive
Messages sorted by:
Re: Airthmetic confusion...
- X-seq: zsh-users 8840
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: Airthmetic confusion...
- Date: Tue, 17 May 2005 03:48:52 +0000
- In-reply-to: <20050517.051316.74748513.Meino.Cramer@xxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20050516.195529.74749456.Meino.Cramer@xxxxxx> <20050516224332.246839a4@localhost> <3060c239050516135933fd2ff6@xxxxxxxxxxxxxx> <20050517.051316.74748513.Meino.Cramer@xxxxxx>
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: