[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#473156: [checks/scripts] dash now supports $((cnt+1))



On Fri, 2008-03-28 at 11:31 -0700, Russ Allbery wrote:
> "Adam D. Barratt" <adam@adam-barratt.org.uk> writes:
[...]
> > dash (finally) gained support for the shell arithmetic construct "$((var
> > +1))" with the upload of 0.5.4-3 in December 2007 (see #329025).
> >
> > As lenny contains a version of dash with the support, I've attached a
> > patch removing the corresponding test from the bashisms section of
> > checks/scripts.
> 
> dash is not the metric for bashisms, though.  If it's not in POSIX and
> isn't listed as an exception in Policy 10.4, it's not allowed for /bin/sh
> scripts.

I realise that. :-) The comment against the check does say "doesn't work
in dash", although I realise that's merely informative.

> Do you think we should add this as an additional exception?

As far as I can see, it *is* in POSIX, which is what persuaded Herbert
to (albeit slowly) add it to dash.

<quote>
2.6.4 Arithmetic Expansion
Arithmetic expansion provides a mechanism for evaluating an arithmetic
expression and substituting its value. The format for arithmetic
expansion shall be as follows:

        $((expression))
[...]
Next, the shell shall treat this as an arithmetic expression and
substitute the value of the expression. The arithmetic expression shall
be processed according to the rules given in Arithmetic Precision and
Operations , with the following exceptions:

      * Only signed long integer arithmetic is required.
[...]
If the shell variable x contains a value that forms a valid integer
constant, then the arithmetic expansions "$((x))" and "$(($x))" shall
return the same value.
</quote>

My reading of the above is that "$((var+1))" is valid and that the
comment against the check was correct - i.e. it's not a bashism at all,
but was being checked for simply because dash did not correctly support
the syntax despite it being permitted by POSIX with no extensions.

As a further data point, posh supports both $((var+1)) and $((var=1)).

Adam



Reply to: