Austin Group Defect Tracker

Aardvark Mark IV


Viewing Issue Simple Details Jump to Notes ] Issue History ] Print ]
ID Category Severity Type Date Submitted Last Update
0000888 [1003.1(2013)/Issue7+TC1] Shell and Utilities Objection Clarification Requested 2014-11-05 17:00 2019-06-10 08:54
Reporter geoffclare View Status public  
Assigned To
Priority normal Resolution Accepted  
Status Closed  
Name Geoff Clare
Organization The Open Group
User Reference
Section 2.5.2 Special Parameters
Page Number 2324
Line Number 73742-73754
Interp Status Approved
Final Accepted Text See Note: 0002547.
Summary 0000888: Clarify expansion of '@' and '*' special parameters
Description An email thread started by Stephane Chazelas identified some ways in
which the standard is unclear regarding the expansion of the '@' and
'*' special parameters.

Note that the proposed changes make it optional whether fields
resulting from empty positional parameters are discarded when $@ and
$* are subject to field splitting. This is to allow the existing
variation in behaviour for TC2. A separate enhancement request
should be submitted to change "may" to "shall", and remove the
relevant "optional" output lines in the examples, in order to tighten
this up for Issue 8.
Desired Action On Page: 2324 Line: 73742-73754 Section: 2.5.2 Special Parameters

Replace the descriptions of the '@' and '*' special parameters with:

@
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 [xref to 2.6.5 Field Splitting]. When the expansion occurs within double-quotes, the behavior is unspecified unless one of the following is true:

* Field splitting as described in [xref to 2.6.5 Field Splitting] would be performed if the expansion were not within double-quotes (regardless of whether field splitting would have any effect, for example if IFS is null).

* The double-quotes are within the word of a ${parameter:-word} or a ${parameter:+word} expansion (with or without the <colon>; see [xref to 2.6.2 Parameter Expansion]) which would have been subject to field splitting if parameter had been expanded instead of word.

If one of these conditions is true, the initial fields shall be retained as separate fields except that, if the parameter being expanded was embedded within a word, the first field shall be joined with the beginning part of the original word and the last field shall be joined with the end part of the original word. In all other contexts the results of the expansion are unspecified. If there are no positional parameters, the expansion of '@' shall generate zero fields, even when '@' is within double-quotes; however, if the expansion is embedded within a word which contains one or more other parts that expand to a quoted null string, these null string(s) shall still produce an empty field, except that if the other parts are all within the same double-quotes as the '@', it is unspecified whether the result is zero fields or one empty field.

*
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 [xref to 2.6.5 Field Splitting]. When the expansion occurs in a context where field splitting will not be performed, the initial fields shall be joined to form a single field with the value of each parameter separated by the first character of the IFS variable if IFS contains at least one character, or separated by a <space> if IFS is unset, or with no separation if IFS is set to a null string.

On Page: 2325 Line: 73791 Section: 2.5.3 Shell Variables

In the description of IFS, change from:

A string treated as a list of characters that is used for field splitting and to split lines into fields with the read command.

If IFS is not set, it shall behave as normal for an unset variable, except that field splitting by the shell and line splitting by the read command shall

to:

A string treated as a list of characters that is used for field splitting, expansion of the '*' special parameter, and to split lines into fields with the read utility. If the value of IFS includes any bytes that do not form part of a valid character, the results of field splitting, expansion of '*', and use of the read utility are unspecified.

If IFS is not set, it shall behave as normal for an unset variable, except that field splitting by the shell and line splitting by the read utility shall

On Page: 2328 Line: 73940 Section: 2.6.2 Parameter Expansions

Change from:

Field splitting shall not be performed on the results of the expansion, with the exception of '@'; see [xref to 2.5.2].

to:

Field splitting shall not be performed on the results of the expansion.

On Page: 3191 Line: 106806 Section: sh

In the ENVIRONMENT VARIABLES section, for IFS change from:

A string treated as a list of characters that is used for field splitting and to split lines into fields with the read command.

If IFS is not set, it shall behave as normal for an unset variable, except that field splitting by the shell and line splitting by the read command shall

to:

A string treated as a list of characters that is used for field splitting, expansion of the '*' special parameter, and to split lines into fields with the read utility. If the value of IFS includes any bytes that do not form part of a valid character, the results of field splitting, expansion of '*', and use of the read utility are unspecified.

If IFS is not set, it shall behave as normal for an unset variable, except that field splitting by the shell and line splitting by the read utility shall

Cross-volume changes to XRAT...

On Page: 3680 Line: 125783-125803 Section: C.2.5.2 Special Parameters

Change from:

Some examples of the '*' and '@' properties, including the concatenation aspects:
set "abc" "def ghi" "jkl"

echo $* => "abc" "def" "ghi" "jkl"
echo "$*" => "abc def ghi jkl"
echo $@ => "abc" "def" "ghi" "jkl"
but:
echo "$@" => "abc" "def ghi" "jkl"
echo "xx$@yy" => "xxabc" "def ghi" "jklyy"
echo "$@$@" => "abc" "def ghi" "jklabc" "def ghi&quo
t; "jkl"
In the preceding examples, the double-quote characters that appear after the "=>" do not appear in the output and are used only to illustrate word boundaries.

The following example illustrates the effect of setting IFS to a null string:

$ IFS=''
$ set foo bar bam
$ echo "$@"
foo bar bam
$ echo "$*"
foobarbam
$ unset IFS
$ echo "$*"
foo bar bam

to:

The following examples illustrate some of the ways in which '*' and '@' can be expanded:

<tt>set "abc" "def ghi" "jkl"
unset novar
IFS=' ' # a space
printf '%s\n' $*
abc
def
ghi
jkl

printf '%s\n' "$*"
abc def ghi jkl
printf '%s\n' xx$*yy
xxabc
def
ghi
jklyy

printf '%s\n' "xx$*yy"
xxabc def ghi jklyy
printf '%s\n' $@
abc
def
ghi
jkl

printf '%s\n' "$@"
abc
def ghi
jkl

printf '%s\n' ${1+"$@"}
abc
def ghi
jkl

printf '%s\n' ${novar-"$@"}
abc
def ghi
jkl

printf '%s\n' xx$@yy
xxabc
def
ghi
jklyy

printf '%s\n' "xx$@yy"
xxabc
def ghi
jklyy

printf '%s\n' $@$@
abc
def
ghi
jklabc
def
ghi
jkl

printf '%s\n' "$@$@"
abc
def ghi
jklabc
def ghi
jkl

IFS=':'
printf '%s\n' "$*"
abc:def ghi:jkl
var=$*; printf '%s\n' "$var"
abc:def ghi:jkl
var="$*"; printf '%s\n' "$var"
abc:def ghi:jkl
unset var
printf '%s\n' ${var-$*}
abc
def ghi
jkl

printf '%s\n' "${var-$*}"
abc:def ghi:jkl
printf '%s\n' ${var-"$*"}
abc:def ghi:jkl
printf '%s\n' ${var=$*}
abc
def ghi
jkl

printf 'var=%s\n' "$var"
var=abc:def ghi:jkl
unset var
printf '%s\n' "${var=$*}"
abc:def ghi:jkl
printf 'var=%s\n' "$var"
var=abc:def ghi:jkl

IFS='' # null
printf '%s\n' "$*"
abcdef ghijkl
var=$*; printf '%s\n' "$var"
abcdef ghijkl
var="$*"; printf '%s\n' "$var"
abcdef ghijkl
unset var
printf '%s\n' ${var-$*}
abcdef ghijkl
printf '%s\n' "${var-$*}"
abcdef ghijkl
printf '%s\n' ${var-"$*"}
abcdef ghijkl
printf '%s\n' ${var=$*}
abcdef ghijkl
printf 'var=%s\n' "$var"
var=abcdef ghijkl
unset var
printf '%s\n' "${var=$*}"
abcdef ghijkl
printf 'var=%s\n' "$var"
var=abcdef ghijkl
printf '%s\n' "$@"
abc
def ghi
jkl


unset IFS
printf '%s\n' "$*"
abc def ghi jkl
var=$*; printf '%s\n' "$var"
abc def ghi jkl
var="$*"; printf '%s\n' "$var"
abc def ghi jkl
unset var
printf '%s\n' ${var-$*}
abc
def
ghi
jkl

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

printf 'var=%s\n' "$var"
var=abc def ghi jkl
unset var
printf '%s\n' "${var=$*}"
abc def ghi jkl
printf 'var=%s\n' "$var"
var=abc def ghi jkl
printf '%s\n' "$@"
abc
def ghi
jkl


set one "" three
printf '[%s]\n' $*
[one]
[]
</tt> (this line of output is optional)<tt>
[three]
printf '[%s]\n' $@
[one]
[]
</tt> (this line of output is optional)<tt>
[three]

set --
printf '[%s]\n' foo "$*"
[foo]
[]

printf '[%s]\n' foo "$novar$*$(echo)"
[foo]
[]

printf '[%s]\n' foo $@
[foo]
printf '[%s]\n' foo "$@"
[foo]
printf '[%s]\n' foo ''$@
[foo]
[]

printf '[%s]\n' foo ''"$@"
[foo]
[]

printf '[%s]\n' foo "$novar$@$(echo)"
[foo]
[]
</tt> (this line of output is optional)<tt>
printf '[%s]\n' foo ''"$novar$@$(echo)"
[foo]
[]
</tt>

In all of the following commands the results of the expansion of '@' (if performed) are unspecified:

<tt>var=$@
var="$@"
printf '%s\n' ${var=$@}
printf '%s\n' "${var=$@}"
printf '%s\n' ${var="$@"}
printf '%s\n' ${var?$@}
printf '%s\n' "${var?$@}"
printf '%s\n' ${var?"$@"}
printf '%s\n' ${#@}
printf '%s\n' "${#@}"
printf '%s\n' ${@%foo}
printf '%s\n' "${@%foo}"
printf '%s\n' ${@#foo}
printf '%s\n' "${@#foo}"
printf '%s\n' ${var%$@}
printf '%s\n' "${var%$@}"
printf '%s\n' ${var%"$@"}
printf '%s\n' ${var%%$@}
printf '%s\n' "${var%%$@}"
printf '%s\n' ${var%%"$@"}
printf '%s\n' ${var#$@}
printf '%s\n' "${var#$@}"
printf '%s\n' ${var#"$@"}
printf '%s\n' ${var##$@}
printf '%s\n' "${var##$@}"
printf '%s\n' ${var##"$@"}</tt>
Tags tc2-2008
Attached Files

- Relationships

-  Notes
(0002430)
geoffclare (manager)
2014-11-05 17:21

Note that the &quot in the line beginning

echo "$@$@" =>

in the desired action is not in the submitted text - it seems to be generated by Mantis.
(0002547)
Don Cragun (manager)
2015-02-19 16:27
edited on: 2015-02-19 16:32

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:
-------------
Remove the ambiguity.

Notes to the Editor (not part of this interpretation):
-------------------------------------------------------
Make the changes suggested in the Desired Action.

(0002553)
ajosey (manager)
2015-02-20 12:13

Interpretation proposed 20 Feb 2015
(0002600)
ajosey (manager)
2015-03-23 12:09

Interpretation approved 23rd March 2015

- Issue History
Date Modified Username Field Change
2014-11-05 17:00 geoffclare New Issue
2014-11-05 17:00 geoffclare Name => Geoff Clare
2014-11-05 17:00 geoffclare Organization => The Open Group
2014-11-05 17:00 geoffclare Section => 2.5.2 Special Parameters
2014-11-05 17:00 geoffclare Page Number => 2324
2014-11-05 17:00 geoffclare Line Number => 73742-73754
2014-11-05 17:00 geoffclare Interp Status => ---
2014-11-05 17:11 geoffclare Desired Action Updated
2014-11-05 17:17 geoffclare Desired Action Updated
2014-11-05 17:21 geoffclare Note Added: 0002430
2015-02-19 16:23 geoffclare Desired Action Updated
2015-02-19 16:27 Don Cragun Interp Status --- => Pending
2015-02-19 16:27 Don Cragun Note Added: 0002547
2015-02-19 16:28 Don Cragun Final Accepted Text => See Note: 0002547.
2015-02-19 16:28 Don Cragun Status New => Interpretation Required
2015-02-19 16:28 Don Cragun Resolution Open => Accepted
2015-02-19 16:28 Don Cragun Tag Attached: tc2-2008
2015-02-19 16:32 Don Cragun Note Edited: 0002547
2015-02-20 12:13 ajosey Interp Status Pending => Proposed
2015-02-20 12:13 ajosey Note Added: 0002553
2015-03-23 12:09 ajosey Interp Status Proposed => Approved
2015-03-23 12:09 ajosey Note Added: 0002600
2019-06-10 08:54 agadmin Status Interpretation Required => Closed


Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker