bug-bash
[Top][All Lists]
Advanced

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

Re: bash 'let' can give error


From: Eric Blake
Subject: Re: bash 'let' can give error
Date: Fri, 10 Dec 2010 08:54:09 -0700
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.12) Gecko/20101103 Fedora/1.0-0.33.b2pre.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.6

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   address@hidden    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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