A NOTE has been added to this issue. ====================================================================== https://www.austingroupbugs.net/view.php?id=1649 ====================================================================== Reported By: kre Assigned To: ====================================================================== Project: Issue 8 drafts Issue ID: 1649 Category: Shell and Utilities Type: Error Severity: Objection Priority: normal Status: New Name: Robert Elz Organization: User Reference: Section: XCU 2.6.5 Page Number: 2476 Line Number: 80478 - 80504 Final Accepted Text: ====================================================================== Date Submitted: 2023-03-31 01:55 UTC Last Modified: 2023-09-07 14:15 UTC ====================================================================== Summary: Field splitting is woefully under specified, and in places, simply wrong ======================================================================
---------------------------------------------------------------------- (0006460) kre (reporter) - 2023-09-07 14:15 https://www.austingroupbugs.net/view.php?id=1649#c6460 ---------------------------------------------------------------------- 2.6.5 Field Splitting After parameter expansion (Section 2.6.2), command substitution (Section 2.6.3), and arithmetic expansion (Section 2.6.4), and if the shell variable IFS is set, and its value is not empty, or if IFS is unset, the shell shall scan each field containing results of expansions and substitutions that did not occur in double-quotes for field splitting and multiple fields can result. If IFS is set with an empty string as its value, no field splitting occurs, however if an input field which contained expansions or substitutions is entirely empty, it shall be removed. Note that this occurs before quote removal, any input field that contains any quoting characters can never be empty at this point. Fields which contain no unquoted results from any of the expansions or substitutions shall not be affected by field splitting, and shall remain unaltered. In the following description, it is assumed that there is in the field at least one unquoted expansion or substitution result present, this assumption will not be restated. Field splitting only considers altering those parts of the field. For the purposes of this section, the term "IFS white space" shall mean any of the characters <space> <tab> or <newline> which are present in the value of the IFS variable. It is implementation defined whether other White Space characters which appear in the value of IFS are also considered as "IFS white space". If the IFS variable is unset, then for the purposes of this section, but without altering the value of the variable, its value shall be considered to contain the three characters <space> <tab> and <newline>, all of which are IFS white space characters. The three characters above defined as IFS white space characters are always IFS white space, when they occur in the value of IFS, for other locale specific White Space characters allowed by the implementation it is unspecified whether the character is considered as IFS white space if it is White Space at the time it is assigned to the IFS variable, or if it is White Space at the time field splitting occurs (the locale may have altered between those events). The shell shall treat non-empty sequences formed from the characters in the IFS value, in any order, provided that no sequence contains more than one character that is not IFS white space, and use the delimiters as field terminators to split the results of parameter expansion, command substitution, and arithmetic expansion into separate fields, as described below. Note that these delimiters terminate a field, they do not, of themselves, cause a new one to start, subsequent non IFS whitespace characters in the field are required for a new field to begin. If results of the algorithm are that no fields are delimited, that is, if the input is wholly empty or consists entirely of IFS white space, the result shall be zero fields (rather than an empty field). For the purposes of this section, when a field is said to be delimited, then the characters from the input from after the delimiter which terminated the previous field, or from the beginning of the input if this is the first, up to the point immediately preceding the delimiter, shall be considered as a candidate for forming an output field. If that candidate is not empty, or if both the previous output field (if any), and the current field being delimited were delimited a delimiter that includes a character which is not IFS white space, then the candidate shall become an output field. If the current candidate output field is empty, and either it, or the previous output field were delimited by only IFS white space, then the empty candidate shall be removed, and shall not form an output field. Each expansion, or substitution shall be processed in order as follows, examining characters in the input field, left to right, and beginning with an empty candidate field: While the input is not empty... When instructed to perform the next iteration, start again here, with the input as modified. Consider the first remaining character of the input. If it is: a. A character that did not result from an unquoted expansion or substitution: Append this character to the candidate, and remove it from the input. Next iteration of the loop. b. A character in the input that is not a character in IFS: Append this character to the candidate, and remove it from the input. Next iteration. c. An IFS white space character: Remove that character from the input, advance to the next input character, and repeat this step. d. Another IFS character, not IFS white space: Remove that character from the input, but note it was observed. Remove any immediately following IFS white space characters from the input. At this point, if the candidate is not empty, or if a non IFS white space character was seen at step d, then the candidate becomes an output field. In either case, empty the candidate, and perform the next iteration. When the input is empty, if the candidate is not empty, it becomes an output field. The set of output fields so produced, which may be none, replaces the input field. Issue History Date Modified Username Field Change ====================================================================== 2023-03-31 01:55 kre New Issue 2023-03-31 01:55 kre File Added: ifs 2023-03-31 01:55 kre Name => Robert Elz 2023-03-31 01:55 kre Section => XCU 2.6.5 2023-03-31 01:55 kre Page Number => 2476 2023-03-31 01:55 kre Line Number => 80478 - 80504 2023-07-31 16:13 Don Cragun Note Added: 0006412 2023-09-07 14:14 kre Note Added: 0006459 2023-09-07 14:15 kre Note Added: 0006460 ======================================================================