View Issue Details

IDProjectCategoryView StatusLast Update
00000501003.1(2008)/Issue 7Shell and Utilitiespublic2013-04-16 13:06
Reportergeoffclare Assigned Toajosey  
PrioritynormalSeverityObjectionTypeClarification Requested
Status ClosedResolutionAccepted 
NameGeoff Clare
OrganizationThe Open Group
User Reference
Section2.6.4
Page Number2310
Line Number72861
Interp StatusApproved
Final Accepted Text0000050:0000228
Summary0000050: acceptance of shell variables with negative values is not clear
DescriptionXCU 2.6.4 states:

    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.

This seems fine at face value, but earlier in the same section is
the following statement:

    Only the decimal-constant, octal-constant, and
    hexadecimal-constant constants specified in the ISO C standard,
    Section 6.4.4.1 are required to be recognized as constants.

This statement is specifically about arithmetic expressions, but
could be taken to affect the requirements about shell variable
contents as well. In which case, shell variables containing
negative values are not required to be supported.

When clarifying this for minus signs, it is probably worth including
plus signs as well. All the shells I have tried accept:

    x='+2'; echo $((x))

This is also consistent with the printf utility, which is required to
accept constants "as described by the ISO C standard, with the
following extensions: * A leading plus or minus sign shall be allowed".

In addition, in the later statement:

    If the expression is invalid, the expansion fails and the shell
    shall write a message to standard error indicating the failure.

it is not clear whether this only applies to the expression itself,
or also to the contents of shell variables used in the expression.
Since shells can, as an extension, support the use of variables with
non-constant contents, the change here needs to be carefully worded so
as not to imply that anything that is not a valid constant produces an
error.
Desired ActionChange

    "If the shell variable x contains a value that forms a valid
    integer constant, then"

to

    "If the shell variable x contains a value that forms a valid
    integer constant, optionally including a leading plus or minus
    sign, then"

At line 72866, change

    "If the expression is invalid, the expansion fails and the shell
    shall write a message to standard error indicating the failure."

to

    "If the expression is invalid, or the contents of a shell variable
    used in the expression are not recognized by the shell, the
    expansion fails and the shell shall write a diagnostic message to
    standard error indicating the failure."
Tagstc1-2008

Activities

Don Cragun

2009-06-25 12:57

manager   bugnote:0000088

Last edited: 2009-06-26 06:30

Originally reported by gwc:xxxxxxxxxxxxx
Thu, 19 Feb 2009 15:17:22 +0000
with Subject: Defect in XCU 2.6.4

Transcribed by Don Cragun from xcubug3.txt ERN 6

Submitter tag "gwc shell integer constants"

ajosey

2009-09-17 15:13

manager   bugnote:0000228

Last edited: 2009-10-09 16:02

Interpretation response
------------------------

The standard is unclear on this issue, and no conformance
distinction can be made between alternative implementations based
on this. This is being referred to the sponsor.


Rationale:
-------------
None.

Notes to the Editor (not part of this interpretation):
-------------------------------------------------------

Make the change suggested by the submitter

Issue History

Date Modified Username Field Change
2009-06-25 12:53 Don Cragun New Issue
2009-06-25 12:53 Don Cragun Status New => Under Review
2009-06-25 12:53 Don Cragun Assigned To => ajosey
2009-06-25 12:53 Don Cragun Name => Geoff Clare
2009-06-25 12:53 Don Cragun Organization => The Open Group
2009-06-25 12:53 Don Cragun Section => 2.6.4
2009-06-25 12:53 Don Cragun Page Number => 2310
2009-06-25 12:53 Don Cragun Line Number => 72861
2009-06-25 12:57 Don Cragun Note Added: 0000088
2009-06-25 12:57 Don Cragun Reporter Don Cragun => geoffclare
2009-06-25 12:57 Don Cragun Status Under Review => Resolved
2009-06-25 12:57 Don Cragun Resolution Open => Accepted
2009-06-25 16:38 Don Cragun Tag Attached: real bug in aardvark
2009-06-26 06:30 Don Cragun Note Edited: 0000088
2009-07-30 16:07 msbrown Tag Detached: real bug in aardvark
2009-07-30 16:09 msbrown Status Resolved => Interpretation Required
2009-08-11 16:22 Don Cragun Interp Status => Pending
2009-09-17 15:13 ajosey Note Added: 0000228
2009-09-17 15:14 ajosey Final Accepted Text => 0000050:0000228
2009-09-17 15:41 nick Interp Status Pending => Proposed
2009-10-09 15:50 ajosey Note Edited: 0000228
2009-10-09 15:56 ajosey Interp Status Proposed => Approved
2009-10-09 16:02 ajosey Note Edited: 0000228
2010-09-20 09:02 geoffclare Tag Attached: tc1-2008
2013-04-16 13:06 ajosey Status Interpretation Required => Closed