Date: Tue, 26 Feb 2013 18:27:04 GMT From: ZAHEMSZKY@FreeBSD.org, Gabor <Gabor@Zahemszky.HU> To: freebsd-gnats-submit@FreeBSD.org Subject: bin/176444: strange behaviour of the $(( )) form in sh(1) Message-ID: <201302261827.r1QIR4MT017392@red.freebsd.org> Resent-Message-ID: <201302261830.r1QIU1x4043789@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>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@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:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201302261827.r1QIR4MT017392>