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
0000974 [1003.1(2013)/Issue7+TC1] Shell and Utilities Editorial Error 2015-08-10 11:09 2019-10-21 09:22
Reporter stephane View Status public  
Assigned To
Priority normal Resolution Accepted As Marked  
Status Applied  
Name Stephane Chazelas
Organization
User Reference
Section awk
Page Number 2460
Line Number 78773-78782
Interp Status Approved
Final Accepted Text See Note: 0003231
Summary 0000974: several issues with awk's ARGC/ARGV
Description The description of ARGC/ARGV in the awk specification implies that it contains the list of arguments (to the exclusion of progname) while all awk implementations that I tried have the basename of the argv[0] that awk received in ARGV[0].

It also doesn't specify what should happen if one sets ARGC to 0 or 1, or what the effect of assigning ARGV[0] may be. Or of assigning all of ARGV[1]..ARGV[ARGC-1] to null.

It doesn't say what's the consequence of doing: c=ARGC; ARGC=0; ARGC=c (whether setting ARGC=0 would truncate the ARGV array).
Desired Action Specify that ARGV[0] is the basename(argv[0]) and is otherwise not used and assigning a value to it has no side effect (it is not used for error reporting by awk for instance in any implementation I tried).

Specifify that setting ARGC to 0 or 1 causes awk to read input from stdin if done from the BEGIN statement. But otherwise setting ARGC to a number that would exclude the currently processed file (as in `awk '{ARGC=1; print}' file`) is unspecified (some awk stop processing after the current record, some at the end of the current file).

Specify that setting or all of ARGV[1]..ARGV[ARGC-1] to null where ARGC > 1 in the BEGIN statement is unspecified (mawk and gawk read from stdin, but heirloom's just exits at the end of the BEGIN statement).

Specify that modifying the value of ARGC doesn't affect the content of ARGV.
Tags tc3-2008
Attached Files

- Relationships
related to 0001451Applied Issue 8 drafts awk ARGV description addition about -v is problematic 

-  Notes
(0002787)
geoffclare (manager)
2015-08-10 13:53

All certified UNIX systems put the full pathname from argv[0] in ARGV[0]. So does GNU awk if you set POSIXLY_CORRECT in the environment:

$ /usr/bin/gawk 'BEGIN { print ARGV[0] }' /dev/null
/usr/bin/gawk
$ (unset POSIXLY_CORRECT; /usr/bin/gawk 'BEGIN { print ARGV[0] }' /dev/null)
gawk
(0002788)
stephane (reporter)
2015-08-10 16:02

We may also want to clarify the expected outcome for things like:

   awk -v ARGC=1 '{print}' file1 file2

(should it read from stdin or file1 and file2?)

or

   awk '{print}' ARGC=3

or

   awk 'BEGIN{ARGV[1] = "ARGC=3"};{print}' file

(should it read from stdin?)
(0003231)
rhansen (manager)
2016-05-19 16:31
edited on: 2016-05-19 16:43

Interpretation response
------------------------
The standard does not speak to this issue, and as such no conformance distinction can be made between alternative implementations based on this. This is being referred to the sponsor.

Rationale:
-------------
None.

Notes to the Editor (not part of this interpretation):
-------------------------------------------------------
On page 2460 line 78773-78779 section awk, change:
ARGC The number of elements in the ARGV array.

ARGV An array of command line arguments, excluding options and the program argument, numbered from zero to ARGC-1.

The arguments in ARGV can be modified or added to; ARGC can be altered. As each input file ends, awk shall treat the next non-null element of ARGV, up to the current value of ARGC-1, inclusive, as the name of the next input file. Thus, setting an element of ARGV to null means that it shall not be treated as an input file. The name '-' indicates the standard input. If an argument matches the format of an assignment operand, this argument shall be treated as an assignment rather than a file argument.
to:
ARGC A number determining when the iteration described for ARGV stops. When an awk program starts, ARGC shall be initialized to the number of elements in the ARGV array. ARGC can be updated by the awk program and by assignment operands. If ARGC is set to a value less than 1, the behavior is unspecified. It is unspecified whether alterations to ARGC can be made using the -v option.

ARGV An array containing, initially, the command name (see [xref to 2.9.1]) used to invoke awk in <tt>ARGV[0]</tt> and the command line arguments, if any, excluding options and the program operand, in <tt>ARGV[1]</tt> through <tt>ARGV[ARGC−1]</tt>. The elements in ARGV can be assigned new values or deleted, and new elements can be added. It is unspecified whether this alteration to ARGV can be made using the -v option.

After processing the BEGIN actions, if any, awk begins interating over the elements of ARGV, processing them as if they were argument operands. It shall behave as if the implementation maintains an internal counter that is initialized to 1 and increments by 1 at the end of each iteration. For each iteration, the following shall occur:
  • If the internal counter is greater than or equal to the current value of ARGC and no file operands have been processed, awk shall set FILENAME to '-' and process standard input as if it was given as a file operand. The internal counter shall not be incremented at the end of this iteration.
  • Otherwise, if the internal counter is greater than or equal to the current value of ARGC, the iterations shall stop and processing of the END actions, if any, shall begin. Any ARGV elements with index values greater than or equal to ARGC shall not be processed as argument operands.
  • Otherwise, if the element <tt>ARGV[</tt>internal counter value<tt>]</tt> does not exist, it is unspecified whether that element is created. No other action shall be taken.
  • Otherwise, if <tt>ARGV[</tt>internal counter value<tt>]</tt> is a null string, no action is taken.
  • Otherwise, if <tt>ARGV[</tt>internal counter value<tt>]</tt> matches the format of an assignment operand (see OPERANDS), awk shall proccess the assignment.
  • Otherwise, <tt>ARGV[</tt>internal counter value<tt>]</tt> shall be treated as a file operand, FILENAME shall be set to that value, and the named file, or standard input if the value is '-', shall be processed as an input file.
Since only non-null elements are processed, setting an element of ARGV to the null string or deleting it means that it shall not be treated as an argument operand.

On page 2460, lines 78798-78800 section awk EXTENDED DESCRIPTION, change the definition of the FILENAME variable:
A pathname of the current input file. Inside a BEGIN action the value is undefined. Inside an END action the value shall be the name of the last input file processed.
to:
The pathname used to open the current input file, or '-' if the file is standard input. Inside a BEGIN action FILENAME shall be unset. Inside an END action the value shall be the name of the last input file processed. If an application changes the value of FILENAME, the results are unspecified.

On page 2453 line 78479 section awk, change:
If no file operands are specified, or if a file operand is '-', the standard input shall be used.
to:
If no file operands or their equivalents, achieved by modifying the awk variables ARGV and ARGC, are specified, or if a file operand is '-', the standard input shall be used.

On page 2453 line 78502 section awk, change:
If there are no file arguments, assignments shall be executed before processing the standard input.
to:
If there are no file arguments or their equivalents, achieved by modifying the awk variables ARGV and ARGC, assignments shall be executed before processing the standard input.

On page 2453 line 78506 section awk, change:
The standard input shall be used only if no file operands are specified, or if a file operand is '-', or if a progfile option-argument is '-'; see the INPUT FILES section.
to:
The standard input shall be used only if no file operands or their equivalents, achieved by modifying the awk variables ARGV and ARGC, are specified; or if a file operand, or its equivalent, is '-'; or if a progfile option-argument is '-'; see the INPUT FILES section.

On page 2453 line 78514 section awk, change:
Standard input in the absence of any file operands
to:
Standard input in the absence of any file operands, or their equivalents

On page 2478 after line 79587 section awk APPLICATION USAGE, add a new paragraph:
To specify a file operand naming a file with a name containing an <equals-sign>, users can use "./" as the first two characters of a relative file pathname that starts with an <underscore> or an alphabetic character to keep the file operand from being interpreted as an assignment operand. Similarly, "./-" can be used to access a file named '-' in the current directory rather than use standard input.


(0003523)
ajosey (manager)
2016-12-15 18:11

Interpretation proposed: 15 Dec 2016
(0003551)
ajosey (manager)
2017-01-18 15:24

Interpretation Approved: 18 Jan 2017

- Issue History
Date Modified Username Field Change
2015-08-10 11:09 stephane New Issue
2015-08-10 11:09 stephane Name => Stephane Chazelas
2015-08-10 11:09 stephane Section => awk
2015-08-10 11:09 stephane Page Number => 2460
2015-08-10 11:09 stephane Line Number => 78773-78782
2015-08-10 13:53 geoffclare Note Added: 0002787
2015-08-10 16:02 stephane Note Added: 0002788
2016-05-19 16:31 rhansen Note Added: 0003231
2016-05-19 16:35 rhansen Note Edited: 0003231
2016-05-19 16:38 rhansen Note Edited: 0003231
2016-05-19 16:39 rhansen Note Edited: 0003231
2016-05-19 16:43 rhansen Note Edited: 0003231
2016-05-19 16:44 rhansen Interp Status => Pending
2016-05-19 16:44 rhansen Final Accepted Text => See Note: 0003231
2016-05-19 16:44 rhansen Status New => Interpretation Required
2016-05-19 16:44 rhansen Resolution Open => Accepted As Marked
2016-05-19 16:44 rhansen Tag Attached: tc3-2008
2016-12-15 18:11 ajosey Interp Status Pending => Proposed
2016-12-15 18:11 ajosey Note Added: 0003523
2017-01-18 15:24 ajosey Interp Status Proposed => Approved
2017-01-18 15:24 ajosey Note Added: 0003551
2019-10-21 09:22 geoffclare Status Interpretation Required => Applied
2021-05-06 15:10 nick Relationship added related to 0001451


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