bug-bash
[Top][All Lists]
Advanced

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

Re: Intriguing error with arithmetic evaluation


From: L. A. Walsh
Subject: Re: Intriguing error with arithmetic evaluation
Date: Mon, 15 Aug 2016 03:15:13 -0700
User-agent: Thunderbird



Chet Ramey wrote:
The relevant change was probably the change in the set of commands to which
`set -e' applies.  The (( command (among others) was added to that list
in bash-4.1.  The change was the result of Posix changing the semantics
of the errexit option and expanding its scope from simple commands to
all commands.

The (( command returns 1 if the expression evaluates to 0.  When `level' is
0, level++ returns a 0 value, and (( returns a status of 1.
That doesn't explain why those not using posix mode should suffer the
arbitrary added incompatibility with previous code.

POSIX was meant to describe existing code -- not cause incompatibilities with
old or current code.

POSIX disbanded and the name has changed hands to be run by people
unassociated with the original POSIX charter -- who created a different
charter.


It would have been nice if the non-posix change would have stayed
compatible with previous versions -- as it was useful in previous verstions
where "-e" could cause a script to exit early if you didn't
remember to check output of every simple command.

If you are writing complex commands, you are already using the
conditional features error code handling.

Calculations shouldn't ever trigger "-e" except for things like
division by 0 (which doesn't trigger it, as the calculation dies
before an return value can be calculated); it's counter-intuitive.

Note, I am not saying ((0)) should return non-zero status, just that it
shouldn't invoke "-e" handling in non-posix mode -- compatible with historical
usage.





reply via email to

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