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


Groups > gnu.bash.bug > #11452

Re: Inconsistent arithmetic evaluation of parameters

Path csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!usenet.stanford.edu!not-for-mail
From Greg Wooledge <wooledg@eeg.ccf.org>
Newsgroups gnu.bash.bug
Subject Re: Inconsistent arithmetic evaluation of parameters
Date Tue, 1 Sep 2015 13:50:30 -0400
Lines 31
Approved bug-bash@gnu.org
Message-ID <mailman.347.1441129866.19560.bug-bash@gnu.org> (permalink)
References <61895190-83A6-4D62-B90E-65023D5E966B@gmail.com>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
X-Trace usenet.stanford.edu 1441129867 23924 208.118.235.17 (1 Sep 2015 17:51:07 GMT)
X-Complaints-To action@cs.stanford.edu
Cc bug-bash@gnu.org
To Clint Hepner <clint.hepner@gmail.com>
Envelope-to bug-bash@gnu.org
Content-Disposition inline
In-Reply-To <61895190-83A6-4D62-B90E-65023D5E966B@gmail.com>
User-Agent Mutt/1.4.2.3i
X-detected-operating-system by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From 139.137.100.1
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:11452

Show key headers only | View raw


On Tue, Sep 01, 2015 at 12:50:23AM -0400, Clint Hepner wrote:
> 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

bar was never changed from its value of 5, so I would say the final
result is correct.

The $(( foo++ )) part is questionable.  You've asked bash to increment
a variable (in a math context), but that variable doesn't have an
integer value.  But it "points to" (contains the name of) a variable
that does.

I would say that any of the following would make sense:

 1) An error message is printed.

 2) foo is unchanged (still contains "bar"), and bar is incremented.

 3) foo takes on the value of bar, and is then incremented.

Bash happens to do #3.

If you think of $(( foo++ )) as being basically equivalent to
$(( tmp=foo, foo=foo+1, tmp )) then #3 is actually quite sensible.

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


Thread

Re: Inconsistent arithmetic evaluation of parameters Greg Wooledge <wooledg@eeg.ccf.org> - 2015-09-01 13:50 -0400

csiph-web