Bug 470794 - arithmetic evaluation doesn't work in all cases
Summary: arithmetic evaluation doesn't work in all cases
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: bash
Version: 4.7
Hardware: All
OS: Linux
medium
medium
Target Milestone: rc
: ---
Assignee: Roman Rakus
QA Contact: BaseOS QE
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2008-11-10 11:03 UTC by Ralph Angenendt
Modified: 2014-01-13 00:08 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2008-11-10 16:31:58 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Ralph Angenendt 2008-11-10 11:03:48 UTC
According to the man page, the following should work:

typeset -i i=0
i+=1
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
+=1"). 

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 16:31:58 UTC
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 16:38:54 UTC
typeset -i i=0
((i+=1))
echo "i == $i"

Comment 3 Ralph Angenendt 2008-11-10 16:47:42 UTC
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).

Sorry.


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