bin/176444: strange behaviour of the $(( )) form in sh(1)

ZAHEMSZKY at FreeBSD.org ZAHEMSZKY at FreeBSD.org
Tue Feb 26 18:30:02 UTC 2013


>Number:         176444
>Category:       bin
>Synopsis:       strange behaviour of the $(( )) form in sh(1)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Feb 26 18:30:00 UTC 2013
>Closed-Date:
>Last-Modified:
>Originator:     ZAHEMSZKY, Gabor
>Release:        9.1-RELEASE
>Organization:
Zahemszky Ltd
>Environment:
FreeBSD Vasarely.Zahemszky.HU 9.1-RELEASE FreeBSD 9.1-RELEASE #0 r243826: Tue Dec  4 06:55:39 UTC 2012     root at obrian.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386

>Description:
In "man sh" it's missing the ++ or -- operator from the description of Arithmetic Expansion. It's OK, as FreeBSD's sh doesn't understand it. But! The main problem, that sh isn't very intelligent in the handling of that form. Look:

$ sh
$ a=1
$ : $(( a++ ))
arithmetic expression: expecting primary: " a++ "
$ echo $a
1
$ : $(( ++a ))
$ echo $a
1
$ : $(( a-- ))
arithmetic expression: expecting primary: " a-- "
$ : $(( --a ))
$ echo $a
1

As you can see, sh correctly generate an error message, if I try to use the postincrement/postdecrement form, but silently ignore my command, when I use the preincrement/predecrement form.
Acrually, at least pdksh and bash knows it, so it should be better if sh understand these operators, too. Or, if it couldn't, it should generate errors in the "pre"-form.
>How-To-Repeat:
Try typing my example commands
>Fix:


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list