NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
bin/50959: /bin/sh does not support 0Xxxx literal constants in $(( )) evaluation
>Number: 50959
>Category: bin
>Synopsis: /bin/sh does not support 0Xxxx literal constants in $(( )) evaluation
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Mar 12 18:15:00 +0000 2016
>Originator: Robert Elz
>Release: NetBSD 7.99.26 (anything to date of this PR)
>Organization:
>Environment:
System: NetBSD andromeda.noi.kre.to 7.99.26 NetBSD 7.99.26 (VBOX64-1.1-20160128) #43: Thu Jan 28 16:09:08 ICT 2016 kre%onyx.coe.psu.ac.th@localhost:/usr/obj/current/kernels/amd64/VBOX64 amd64
Architecture: x86_64
Machine: amd64
>Description:
$(( )) expressions are required to allow decimal, hex, and
octal constants (as operands of the expression - the result
is always decimal.)
NetBSD's /bin/sh does all of that, provided that the hex constant
form uses a lower case 'x' in the leading 0x, rather than upper
case 'X'.
Further, if the hex constant is assigned to a variable, and the
variable name is used in an expression, then hex constants work
regardless of whether it is 0x or 0X. Not very consistent.
>How-To-Repeat:
/bin/sh -c 'echo $(( 0x1 )); echo $(( 0X1 ))' 2>&1
1
sh: arith: syntax error: " 0X1 "
/bin/sh -c 'V=0x1; W=0X1; echo $(( V )) $(( W ))'
1 1
/bin/sh -c 'V=0x1; W=0X1; echo $(( $V )) $(( $W ))'
sh: arith: syntax error: " 0X1 "
Note that in the second, V and W have string values, they are
only converted to integers when used inside $(()). The third
example illustrates that (there's no output in that case as
the whole echo command fails when the syntax error is detected,
but the $V expression would be just fine). This case is just
the same thing as the first of course.
>Fix:
Trivial to fix... already done in my copy, this is another of the
/bin/sh placeholder PRs just to reference when the fix is committed.
Home |
Main Index |
Thread Index |
Old Index