Date: Mon, 23 Jun 2003 08:32:55 +0200 From: des@des.no (Dag-Erling =?iso-8859-1?q?Sm=F8rgrav?=) To: Wartan Hachaturow <wart@tepkom.ru> Cc: freebsd-standards@FreeBSD.org Subject: Re: standards/52972: /bin/sh arithmetic not POSIX compliant Message-ID: <xzp4r2h482w.fsf@dwp.des.no> In-Reply-To: <200306222150.h5MLoGpX061341@freefall.freebsd.org> (Wartan Hachaturow's message of "Sun, 22 Jun 2003 14:50:16 -0700 (PDT)") References: <200306222150.h5MLoGpX061341@freefall.freebsd.org>
index | next in thread | previous in thread | raw e-mail
Wartan Hachaturow <wart@tepkom.ru> writes:
> The following reply was made to PR standards/52972; it has been noted by GNATS.
> On Sun, Jun 22, 2003 at 10:43:27PM +0200, Jens Schweikhardt wrote:
> > The recursive processing requires that $(($a+1)) needs to undergo
> > parameter expansion within $(()).
>
> Right, but this construction works in /bin/sh:
>
> wart@mojo:~$ /bin/sh
> $ a=1
> $ echo $(($a+1))
> 2
Yes. It expands to $((1+1)) which evaluates to 2.
> You've said the problem was with the variable without leading $, like
> this:
> $ a=1
> $ echo $((a+1))
> arith: syntax error: "a+1"
This *should* work, but doesn't.
> And, as far as my English allows me to judge, the quoted part of SUS
> says that "a" in this construct should be left in output as is (since it
> doesn't have leading $, ${, $(, etc.), shouldn't it?
Yes, it should be left as-is so the part of the code that evaluates
arithmetic expressions knows what variable is involved. For instance,
"$(($a+=1)) would expand to "$((1+=1))" before evaluation, which makes
no sense, while "$((a+=1))" clearly says to increase a with 1.
DES
--
Dag-Erling Smørgrav - des@des.no
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?xzp4r2h482w.fsf>
