[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:14:35 -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/09/2010 10:52 AM, Dominic Raferd wrote:
> Description:
>
> $ val=0; let val++; echo $val,$?; unset val
> 1,1
Not a bug.
>
> see the error code 1. Setting any other start value (except undefined)
> for val does not produce this error, the problem occurs for let val++
> and let val-- if the start value is 0.
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.
--
Eric Blake eblake@redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
Re: bash 'let' can give error, Greg Wooledge, 2010/12/10
Re: bash 'let' can give error, Ken Irving, 2010/12/10
Re: bash 'let' can give error, Andreas Schwab, 2010/12/10