On 12/10/2010 08:49 AM, Marc Herbert wrote:
>> let intentionally returns status 1 if the value was 0; and status > 1 if
>> there was an error.  Why?  So you can do loops such as:
>>
>> countdown=10
>> while let countdown--; do ... ; done
>>
>>> Why does this happen? Is it 'by design'?
>>
>> Yes.  The same as for 'expr' which is standardized by POSIX to have the
>> same behavior.
> 
> This is a design mistake: it trades a few characters for a lot of confusion.

It's required for 'expr'.  But since 'let' is a bash extension, bash is
free to change the semantics of 'let' to behave differently.  However,
doing so now would break backwards compatibility with existing scripts
that have come to depend on this behavior, so unfortunately we're stuck
with it.

Remember, non-zero status is NOT always 'failure'; it is the
documentation of each command that will tell you which status values
imply failure.

-- 
Eric Blake   ebl...@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to