Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #11451

Inconsistent arithmetic evaluation of parameters

Path csiph.com!xmission!news.glorb.com!usenet.stanford.edu!not-for-mail
From Clint Hepner <clint.hepner@gmail.com>
Newsgroups gnu.bash.bug
Subject Inconsistent arithmetic evaluation of parameters
Date Tue, 1 Sep 2015 00:50:23 -0400
Lines 56
Approved bug-bash@gnu.org
Message-ID <mailman.345.1441128798.19560.bug-bash@gnu.org> (permalink)
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0 (Mac OS X Mail 8.2 \(2104\))
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding quoted-printable
X-Trace usenet.stanford.edu 1441128799 23157 208.118.235.17 (1 Sep 2015 17:33:19 GMT)
X-Complaints-To action@cs.stanford.edu
To bug-bash@gnu.org
Envelope-to bug-bash@gnu.org
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:content-type:content-transfer-encoding:subject:message-id:date :to:mime-version; bh=EW3G0gQ6QEcKiY88jS9OR4YZFTGKhudmhN3yJuaHNZs=; b=J8MZO89EAsxjXsGSTxj+XUIY+X1pNjSTMOF7iUScb556mWvXzP/0+mCqa9OsQcubvW VUJpJJkzS5hjftGewraegFqBQBYhHM9RseotMz86wwp3LG4ctiyWc+WPu9dXKWlKKC5W fvVtukTDgyAb7md/R6WxmnbszkRBAqFHoEWERUjgX8LobI1V39y+ZAiVPvn1etDlEDCx 9TpLtZjjCHNb8OqTWZfmXdMLljpTr820m0m7GSsZteGcDpR0yq3wetTyOej25KhE/p8B hfuKCG6B01/MgYp5q/EQ5NVnC3G5Qtbc+SZcTiZrj4M7WrcMrlZm8hIT11MrOeOVc42W ZJyQ==
X-Received by 10.140.238.198 with SMTP id j189mr46954416qhc.63.1441083025623; Mon, 31 Aug 2015 21:50:25 -0700 (PDT)
X-Mailer Apple Mail (2.2104)
X-detected-operating-system by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value).
X-Received-From 2607:f8b0:400d:c04::230
X-Mailman-Approved-At Tue, 01 Sep 2015 13:33:17 -0400
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.14
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <http://lists.gnu.org/archive/html/bug-bash>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
Xref csiph.com gnu.bash.bug:11451

Show key headers only | View raw


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.

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Inconsistent arithmetic evaluation of parameters Clint Hepner <clint.hepner@gmail.com> - 2015-09-01 00:50 -0400

csiph-web