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
0001820 [1003.1(2016/18)/Issue7+TC2] Shell and Utilities Comment Enhancement Request 2024-03-14 11:36 2024-03-14 11:36
Reporter mortoneccc View Status public  
Assigned To
Priority normal Resolution Open  
Status New  
Name Ed Morton
Organization
User Reference
Section awk
Page Number 0
Line Number 0
Interp Status ---
Final Accepted Text
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 No tags attached.
Attached Files

- Relationships

There are no notes attached to this issue.

- Issue History
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-03-15 13:50 salewski Issue Monitored: salewski


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