View Issue Details

IDProjectCategoryView StatusLast Update
00011291003.1(2016/18)/Issue7+TC2Shell and Utilitiespublic2024-06-11 09:09
ReporterMcDutchie Assigned To 
PrioritynormalSeverityObjectionTypeError
Status ClosedResolutionAccepted 
NameMartijn Dekker
Organizationmodernish
User Reference
SectionC.2.5
Page Number3724
Line Number127689-127690
Interp Status---
Final Accepted Text
Summary0001129: Incorrect example output of IFS=''; unset var; printf '%s\n' ${var-$*}
DescriptionAccording to the specification (2.5.2 Special Parameters), given null IFS and unset 'var', the output of
    printf '%s\n' ${var-$*}
should be:
    abc
    def ghi
    jkl
and not
    abcdef ghijkl

Reasoning:

First, given an unset 'var', unquoted $* and unquoted ${var-$*} (and unquoted ${1+$*}, etc) should act identically. If they don't, that's a bug either way.

Second, the cited example is contrary to the specification, which says: "Expands to the positional parameters, starting from one, initially producing one field for each positional parameter that is set. When the expansion occurs in a context where field splitting will be performed, any empty fields may be discarded and each of the non-empty fields shall be further split as described in Field Splitting. [...]"

Well, the expansion occurs "in a context where field splitting will be performed" because it is unquoted (the fact that IFS happens to be null is neither here nor there; its value or lack thereof has no bearing on the lexical context). So the non-empty fields, having been generated, "shall be further split as described in Field Splitting", which, given that IFS is null, is a no-op.

In other words, quoted "$*" should join the fields into one, but (given null IFS) unquoted $* should leave the fields alone altogether.

In other words again, unquoted $* should act identically to unquoted $@, hence, unquoted ${var-$*}, ${1+$*}, etc. should act identically to unquoted ${var-$@}, ${1+$@}, etc.

(Note that the case of a default assignment using a parameter substitution, e.g. ${var=$*} given unset 'var', is different; 2.6.2 Parameter Expansion explicitly states for ${parameter:=[word]} that "in all cases, the final value of /parameter/ shall be substituted". So the example in lines 127695-127696 is correct.)
Desired ActionChange the example in lines 127689-127690 to:

    printf '%s\n' ${var-$*}
    abc
    def ghi
    jkl
Tagstc3-2008

Activities

geoffclare

2017-03-21 15:17

manager   bugnote:0003646

My response on the mailing list was:

   Good catch. I agree, we got that case wrong in the examples.

Issue History

Date Modified Username Field Change
2017-03-21 14:32 McDutchie New Issue
2017-03-21 14:32 McDutchie Name => Martijn Dekker
2017-03-21 14:32 McDutchie Organization => modernish
2017-03-21 14:32 McDutchie Section => C.2.5
2017-03-21 14:32 McDutchie Page Number => 3724
2017-03-21 14:32 McDutchie Line Number => 127689-127690
2017-03-21 15:17 geoffclare Note Added: 0003646
2017-03-22 11:50 geoffclare Note View State: 3646: public
2018-08-30 16:21 Don Cragun Interp Status => ---
2018-08-30 16:21 Don Cragun Resolution Open => Accepted
2018-08-30 16:21 Don Cragun Tag Attached: tc3-2008
2018-08-30 16:22 Don Cragun Status New => Resolved
2019-10-31 11:35 geoffclare Status Resolved => Applied
2024-06-11 09:09 agadmin Status Applied => Closed