bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Inconsistent arithmetic evaluation of parameters


From: Clint Hepner
Subject: Inconsistent arithmetic evaluation of parameters
Date: Tue, 1 Sep 2015 00:50:23 -0400

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: darwin14.5.0
Compiler: clang
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' 
-DCONF_OSTYPE='darwin14.5.0' -DCONF_MACHTYPE='x86_64-apple-darwin14.5.0' 
-DCONF_VENDOR='apple' -DLOCALEDIR='/usr/local/Cellar/bash/4.3.42/share/locale' 
-DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -DMACOSX   -I.  -I. -I./include 
-I./lib -I./lib/intl -I/private/tmp/bash20150826-30526-beo5d/bash-4.3/lib/intl  
-DSSH_SOURCE_BASHRC
uname output: Darwin 192.168.1.17 14.5.0 Darwin Kernel Version 14.5.0: Wed Jul 
29 02:26:53 PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64
Machine Type: x86_64-apple-darwin14.5.0

Bash Version: 4.3
Patch Level: 42
Release Status: release

Description:

Parameter names are recursively evaluated in an arithmetic expression, but this
is not done consistently.

Repeat-By:

    foo=bar
    bar=5
    echo $(( foo ))    # produces 5
    echo $(( foo++ ))  # produces 5
    echo $foo          # produces 6, not bar
    echo $bar          # produces 5, not 6


Fix:

It's not clear what should be fixed. First of all, it's not clear what foo
is actually evaluating to. If it evaluates to bar, then bar should be
incremented. If it evaluates to 5, then the autoincrement should be a syntax
error.

It seems like the "correct" behavior would be for a parameter to be evaluated
until its value is a parameter name whose value is an actual integer, such that

    foo=bar
    bar=baz
    baz=5
    echo $(( foo++ ))  # produces 5; result should be baz=6 and foo, bar 
unchanged.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]