Bug 141186 - let incrementing exits 1 when variable value is 0 or undefined
Summary: let incrementing exits 1 when variable value is 0 or undefined
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: bash
Version: 4.0
Hardware: i386
OS: Linux
medium
high
Target Milestone: ---
: ---
Assignee: Tim Waugh
QA Contact: Ben Levenson
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2004-11-29 20:09 UTC by Rob Landry
Modified: 2007-11-30 22:07 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2004-11-29 22:08:01 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Rob Landry 2004-11-29 20:09:02 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.2)
Gecko/20040809

Description of problem:
As above; using let to increase the value of a variable by one for
which the variable is either undefined or containing a value of zero
the exit statis is 1 even though the variable increment accurs correctly.

Version-Release number of selected component (if applicable):
3.0-17

How reproducible:
Always

Steps to Reproduce:
1.bob=0 (or unset bob)
2.let bob++
3.echo $?
    

Actual Results:  prints "1"

Expected Results:  should print "0"; as well because it does not exit
cleanly it causes environments using execfail to bail out prematurely.

Additional info:

Alternate methods appear to work (eg. bob=0; bob=$((bob + 1)); echo
$?); though having to go back and find all of  what AFAIK should be
working code to this alternate is not ideal and likely to cause
problems outside of hwcert (my particular interest in this bug).

I set the sev. to high since it causes the USB test to bail out early;
though please set accordingly if this does not seem appropriate.

Comment 1 Rob Landry 2004-11-29 21:09:42 UTC
perhaps a nueance of evaluation order as 'let ++bob' also exits zero?

Comment 2 Rob Landry 2004-11-29 21:31:25 UTC
should also mention that in either case $bob contains the correct
value; if ++bob is more correct and bob++ is incorrect should it not
not of effected the value of $bob since the command is invalid?;
alternatively I would have to argue that the exit code in either case
should be 0 if the command executes correctly; oh well.  Let me know
which is which.

Comment 3 Tim Waugh 2004-11-29 22:08:01 UTC
As documented in the man page.  bob++ evaluates to 0, and so 1 is
returned.

Comment 4 Rob Landry 2004-11-29 22:57:00 UTC
I'm still confused on how 0 + 1 evaluates to 0 while 1 + 0 evaluates
to 1; but if say so.  Course I never understood... unset bob; [ -n bob
]; echo $? (returns 0); bob=foo; [ -n bob ]; echo $? (returns 0) either :)

Comment 5 Tim Waugh 2004-11-30 08:38:24 UTC
    let arg [arg ...]
         Each arg is an  arithmetic  expression  to  be  evaluated  (see
         ARITHMETIC  EVALUATION).   If  the last arg evaluates to 0, let
         returns 1; 0 is returned otherwise.


Note You need to log in before you can comment on or make changes to this bug.