Email List: Xaustin-group-lX
[All Lists]

Re: shell, arithmetic expansion and integer constants

To: austin-group-l@xxxxxxxxxxxxx
Subject: Re: shell, arithmetic expansion and integer constants
From: Vincent Lefevre <vincent-opgr@xxxxxxxxxx>
Date: Tue, 17 Jun 2008 18:14:39 +0200
Mail-followup-to: austin-group-l@opengroup.org
References: <20080617140716.GN10734@prunille.vinc17.org> <20080617152424.GA31235@squonk.masqnet>
On 2008-06-17 16:24:24 +0100, Geoff Clare wrote:
> Vincent Lefevre <vincent-opgr@vinc17.org> wrote, on 17 Jun 2008:
> >
> > Concerning arithmetic expansion, POSIX says[*]:
> > 
> >   If the expression is invalid, the expansion fails and the shell
> >   shall write a message to standard error indicating the failure.
> > 
> > [*] 
>http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_04
> > 
> > But it doesn't seem to say anything if a variable contains an
> > invalid value.
> 
> I think this was intentional, in order to allow implementations
> to support things like x=1+1 if they wish.

Note that 1+1 could be regarded as valid by the shell. (POSIX says
that some forms of integer constants must be recognized, but doesn't
say that the shell cannot recognize other forms.)

What I have in mind is that either the shell can handle the value as
a constant or the shell shall output an error message. It seems that
in practice most (if not all) shells behave that way. Behaviors like
exiting upon invalid value would not be allowed (as the behavior is
currently unspecified, I'd say that a shell can currently exit with
such an invalid value).

> > but it also explicitly says that a real-floating type can be used
> > instead of signed long, and I think that the equivalence between
> > "$((x))" and "$(($x))" should be required even through extensions.
> 
> I don't think POSIX can place requirements on the behaviour of
> extensions (other than the obvious one that they are compatible,
> i.e. don't conflict, with the standard).  If we wanted to require
> equivalence of $((x)) and $(($x)) for real-floating values, we would
> have to specify real-floating support as an option, rather than just
> an allowed extension.

OK.

-- 
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)

<Prev in Thread] Current Thread [Next in Thread>