Bug 9861 - Posix 12.2 Guideline 9 violation: options parsed after operands (found on awk)
Summary: Posix 12.2 Guideline 9 violation: options parsed after operands (found on awk)
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Standard Compliance (show other bugs)
Version: 1.23.x
Hardware: All Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-05-11 19:19 UTC by camerisdump
Modified: 2017-08-16 17:09 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description camerisdump 2017-05-11 19:19:59 UTC
busybox, at least its awk utility, does not conform to Posix 12.2 Guideline 9 (http://pubs.opengroup.org/onlinepubs/9699919799/), options come before operands, hence arguments after the first operand should not tried to be parsed as options:  
  $ awk 'BEGIN { for(i=1; i<ARGC; ++i) { print i ": " ARGV[i] }}' -some --args
  awk: invalid option -- s

  $ gawk 'BEGIN { for(i=1; i<ARGC; ++i) { print i ": " ARGV[i] }}' -some --args
  1: -some
  2: --args

the awk-program clearly is the first operand. another example:

  $ awk 'BEGIN { for(i=1; i<ARGC; ++i) { print i ": " ARGV[i] }}' -- -some --args
  1: -some
  2: --args

  $ gawk 'BEGIN { for(i=1; i<ARGC; ++i) { print i ": " ARGV[i] }}' -- -some --args
  1: --
  2: -some
  3: --args

workaround, explicitly declare end of options before the program:

  $ awk -- 'BEGIN { for(i=1; i<ARGC; ++i) { print i ": " ARGV[i] }}' -some --args
  1: -some
  2: --args

  $ gawk -- 'BEGIN { for(i=1; i<ARGC; ++i) { print i ": " ARGV[i] }}' -some --args
  1: -some
  2: --args

In other words, the first argument that is not an option or option-argument should have the same effect as encountering the -- argument.

Unfortunatley I can't think of any other utility that could also be affected by this.
Comment 1 Denys Vlasenko 2017-08-16 17:09:39 UTC
Fixed in git.