[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Curious case of arithmetic expansion
From: 
Eduardo Bustamante 
Subject: 
Re: Curious case of arithmetic expansion 
Date: 
Sun, 23 Apr 2017 18:26:26 0500 
On Sun, Apr 23, 2017 at 3:25 PM, Florian Mayer <address@hidden> wrote:
[...]
> Why not? Why is it not reasonable to expect an intuitive
> result from (())? The most intuitive thing, in my opinion,
> would be to use nameref for side effects by default, because in order
> to get a value from an id, (()) already follows namerefs.
First, the documented behavior
(https://www.gnu.org/software/bash/manual/html_node/ShellArithmetic.html#ShellArithmetic)
is this:
 The *value* of a variable is evaluated as an arithmetic expression
when it is referenced,
 or when a variable which has been given the integer attribute using
‘declare i’ is
 assigned a value
(emphasis is mine)
Second, every other major shell that implements recursive evaluation
of arithmetical expressions behaves the same way as bash:
 address@hidden:~$ for sh in dash mksh zsh ksh93 posh 'busybox sh'
bash; do $sh c 'a=b b=2; echo $((a++)) $a $b'; done
 dash: 1: Illegal number: b
 2 3 2
 2 3 2
 2 3 2
 2 3 2
 2 3 2
 2 3 2

 address@hidden:~$ dpkg l dash mksh zsh ksh posh busybox bash
 Desired=Unknown/Install/Remove/Purge/Hold
  Status=Not/Inst/Conffiles/Unpacked/halFconf/Halfinst/trigaWait/Trigpend
 / Err?=(none)/Reinstrequired (Status,Err: uppercase=bad)
 / Name Version Architecture
Description

+++===========================================================================================================================
 ii bash 4.44+b1 amd64
GNU Bourne Again SHell
 ii busybox 1:1.22.019+b2 amd64
Tiny utilities for small and embedded systems
 ii dash 0.5.82.4 amd64
POSIXcompliant shell
 ii ksh 93u+201208012+b1 amd64
Real, AT&T version of the Korn shell
 ii mksh 542+b2 amd64
MirBSD Korn Shell
 ii posh 0.12.6+b1 amd64
Policycompliant Ordinary SHell
 ii zsh 5.3.14 amd64
shell with lots of features
And third, you haven't really made a compelling argument to change
this behavior. Doing so will break backwards compatibility,
compatibility with other shells that implement this feature, and in my
opinion, doesn't help much in making recursive expansion of
arithmetical expressions more "intuitive".
Why is it so important that this be changed?
 Curious case of arithmetic expansion, Florian Mayer, 2017/04/23
 Re: Curious case of arithmetic expansion, Pierre Gaston, 2017/04/23
 Re: Curious case of arithmetic expansion, Florian Mayer, 2017/04/23
 Re: Curious case of arithmetic expansion, Pierre Gaston, 2017/04/23
 Re: Curious case of arithmetic expansion, Florian Mayer, 2017/04/23
 Re: Curious case of arithmetic expansion, Florian Mayer, 2017/04/23
 Re: Curious case of arithmetic expansion, Pierre Gaston, 2017/04/23
 Re: Curious case of arithmetic expansion, Florian Mayer, 2017/04/23
 Re: Curious case of arithmetic expansion, Chet Ramey, 2017/04/23
 Re: Curious case of arithmetic expansion, Florian Mayer, 2017/04/23
 Re: Curious case of arithmetic expansion,
Eduardo Bustamante <=
 Re: Curious case of arithmetic expansion, Chet Ramey, 2017/04/23
 Re: Curious case of arithmetic expansion, Florian Mayer, 2017/04/24
 Re: Curious case of arithmetic expansion, Steve Amerige, 2017/04/24
 Re: Curious case of arithmetic expansion, Chet Ramey, 2017/04/24