Bug 470794 - arithmetic evaluation doesn't work in all cases
arithmetic evaluation doesn't work in all cases
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: bash (Show other bugs)
All Linux
medium Severity medium
: rc
: ---
Assigned To: Roman Rakus
Depends On:
  Show dependency treegraph
Reported: 2008-11-10 06:03 EST by Ralph Angenendt
Modified: 2014-01-12 19:08 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2008-11-10 11:31:58 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Ralph Angenendt 2008-11-10 06:03:48 EST
According to the man page, the following should work:

typeset -i i=0
echo "i == $i"

Expected output: "i == 1"
Received output:

./t: line 3: i+=1: command not found
i == 0

It works however with strings (output: "i == 11") or, in the above
context with numbers, when preceding the statement with "let" ("let i

It works as expected with bash 3.2 (RHEL 5):

[angenenr@shutdown ~]$typeset -i i=0
[angenenr@shutdown ~]$i+=1
[angenenr@shutdown ~]$echo "i == $i"
i == 1

I have no idea if that might be an upstream bug upto patchlevel 19 (I cannot reach the bash homepage at the moment, patches on the gnu.org mirrors only go upt to 30-16).
Comment 1 Roman Rakus 2008-11-10 11:31:58 EST
According which paragraph and/or section of man page?
In order to "turn on" arithmetic evaluation you should
a) use `let' builtin (man let)
b) use ((expression)) (man bash)

Expected behavior as you mentioned is only in newer bash as feature not as fixed bug. Therefor this is expected behavior.
Comment 2 Roman Rakus 2008-11-10 11:38:54 EST
typeset -i i=0
echo "i == $i"
Comment 3 Ralph Angenendt 2008-11-10 11:47:42 EST
Okay, I don't see a difference between the manual pages of bash 3.2 and 3.0 regarding that. I was referencing 

      declare [-afFirtx] [-p] [name[=value] ...]
      typeset [-afFirtx] [-p] [name[=value] ...]
              Declare variables and/or give them  attributes.   If  no  names  are
              given then display the values of variables.  The -p option will dis-
              play the attributes and values of each name.  When -p is used, addi-
              tional  options  are ignored.  The -F option inhibits the display of
              function definitions; only the  function  name  and  attributes  are
              printed.   If  the extdebug shell option is enabled using shopt, the
              source file name and line number where the function is  defined  are
              displayed as well.  The -F option implies -f.  The following options
              can be used to restrict  output  to  variables  with  the  specified
              attribute or to give variables attributes:
              -i     The  variable is treated as an integer; arithmetic evaluation
                     (see ARITHMETIC EVALUATION ) is performed when  the  variable
                     is assigned a value.

But having rebuilt 3.0.16 from gnu.org, I see the same behaviour. The package name distracted me a bit, I thought we were on patchset 19 (not 15).


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