Bug 141186 - let incrementing exits 1 when variable value is 0 or undefined
let incrementing exits 1 when variable value is 0 or undefined
Status: CLOSED NOTABUG
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: bash (Show other bugs)
4.0
i386 Linux
medium Severity high
: ---
: ---
Assigned To: Tim Waugh
Ben Levenson
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2004-11-29 15:09 EST by Rob Landry
Modified: 2007-11-30 17:07 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2004-11-29 17:08:01 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Rob Landry 2004-11-29 15:09:02 EST
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 16:09:42 EST
perhaps a nueance of evaluation order as 'let ++bob' also exits zero?
Comment 2 Rob Landry 2004-11-29 16:31:25 EST
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 17:08:01 EST
As documented in the man page.  bob++ evaluates to 0, and so 1 is
returned.
Comment 4 Rob Landry 2004-11-29 17:57:00 EST
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 03:38:24 EST
    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.