View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0000974 | 1003.1(2013)/Issue7+TC1 | Shell and Utilities | public | 2015-08-10 11:09 | 2024-06-11 09:02 |
Reporter | stephane | Assigned To | |||
Priority | normal | Severity | Editorial | Type | Error |
Status | Closed | Resolution | Accepted As Marked | ||
Name | Stephane Chazelas | ||||
Organization | |||||
User Reference | |||||
Section | awk | ||||
Page Number | 2460 | ||||
Line Number | 78773-78782 | ||||
Interp Status | Approved | ||||
Final Accepted Text | See 0000974: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 |
related to | 0001451 | Closed | Issue 8 drafts | awk ARGV description addition about -v is problematic |
|
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 |
|
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?) |
|
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.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. 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 operandsto: 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. |
|
Interpretation proposed: 15 Dec 2016 |
|
Interpretation Approved: 18 Jan 2017 |
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 0000974: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 |
2024-06-11 09:02 | agadmin | Status | Applied => Closed |