View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0001820 | 1003.1(2016/18)/Issue7+TC2 | Shell and Utilities | public | 2024-03-14 11:36 | 2024-05-13 15:08 |
Reporter | mortoneccc | Assigned To | |||
Priority | normal | Severity | Comment | Type | Enhancement Request |
Status | Resolved | Resolution | Accepted As Marked | ||
Name | Ed Morton | ||||
Organization | |||||
User Reference | |||||
Section | awk | ||||
Page Number | 0 | ||||
Line Number | 0 | ||||
Interp Status | --- | ||||
Final Accepted Text | 0001820:0006779 | ||||
Summary | 0001820: The impact of changing NF should be stated | ||||
Description | In most modern awks changing the value of NF has these consequences: 1) making it greater than it currently is will add empty fields up to the value of NF, e.g. if NF is currently 5 then doing `NF += 2` will add fields $6 and $7 with empty content. 2) making it less than it currently is will remove fields from the end down to the value of NF, e.g. if NF is currently 5 then doing `NF -= 2` will delete the fields $4 and $5. The alternative to "1" is that we set $(NF+2) = "" and get the same effect but there is no good alternative to "2". To be POSIX compliant today without relying on a specific awk's implementation of undefined behavior we either have to do: split($0,tmp) $0 = "" for ( i=1; i<=(NF-2); i++ ) { $i = tmp[i] } or: sub(/([[:space:]]*[^[:space:]]+){2}[[:space:]]*$/,"") or similar, both with caveats regarding the values of FS and OFS. | ||||
Desired Action | Define the impact of assigning a value to NF similar to the way that assigning a value to $(NF+n) is defined in the spec today: --- assigning to a nonexistent field (for example, $(NF+2)=5) shall increase the value of NF; create any intervening fields with the uninitialized value; and cause the value of $0 to be recomputed, with the fields being separated by the value of OFS. Each field variable shall have a string value or an uninitialized value when created. --- so we would have: --- assigning NF a value greater than it has (for example, NF += 2) shall increase the value of NF; create any intervening fields with the uninitialized value; and cause the value of $0 to be recomputed, with the fields being separated by the value of OFS. Each field variable shall have a string value or an uninitialized value when created. - assigning NF a value less than it has (for example, NF -= 2) shall decrease the value of NF; remove fields from the end of the record down to the new value of NF; and cause the value of $0 to be recomputed, with the fields being separated by the value of OFS. - assigning NF the same value that it already has (for example, NF = NF) shall cause the value of $0 to be recomputed, with the fields being separated by the value of OFS. --- | ||||
Tags | issue9 |
|
On Issue 8 draft 4.1 page 2613 line 85507, change:Field variables shall be designated by a '$' followed by a number or numerical expression. The effect of the field number expression evaluating to anything other than a non-negative integer is unspecified; uninitialized variables or string values need not be converted to numeric values in this context. New field variables can be created by assigning a value to them. References to nonexistent fields (that is, fields after $NF), shall evaluate to the uninitialized value. Such references shall not create new fields. However, assigning to a nonexistent field (for example, $(NF+2)=5) shall increase the value of NF; create any intervening fields with the uninitialized value; and cause the value of $0 to be recomputed, with the fields being separated by the value of OFS. Each field variable shall have a string value or an uninitialized value when created. Field variables shall have the uninitialized value when created from $0 using FS and the variable does not contain any characters. If appropriate, the field variable shall be considered a numeric string (see Expressions in awk, on page 2608). to: Field variables shall be designated by a '$' followed by a number or numerical expression. The effect of the field number expression evaluating to anything other than a non-negative integer is unspecified; uninitialized variables or string values need not be converted to numeric values in this context. Each field variable shall have a string value or an uninitialized value when created. Field variables shall have the uninitialized value when created from $0 using FS and the variable does not contain any characters. If appropriate, the field variable shall be considered a numeric string (see Expressions in awk, on page 2608). |
Date Modified | Username | Field | Change |
---|---|---|---|
2024-03-14 11:36 | mortoneccc | New Issue | |
2024-03-14 11:36 | mortoneccc | Name | => Ed Morton |
2024-03-14 11:36 | mortoneccc | Section | => awk |
2024-03-14 11:36 | mortoneccc | Page Number | => 0 |
2024-03-14 11:36 | mortoneccc | Line Number | => 0 |
2024-05-13 15:07 | geoffclare | Note Added: 0006779 | |
2024-05-13 15:08 | geoffclare | Interp Status | => --- |
2024-05-13 15:08 | geoffclare | Final Accepted Text | => 0001820:0006779 |
2024-05-13 15:08 | geoffclare | Status | New => Resolved |
2024-05-13 15:08 | geoffclare | Resolution | Open => Accepted As Marked |
2024-05-13 15:09 | geoffclare | Tag Attached: issue9 |