Bug 9861

Summary: Posix 12.2 Guideline 9 violation: options parsed after operands (found on awk)
Product: Busybox Reporter: camerisdump
Component: Standard ComplianceAssignee: unassigned
Status: RESOLVED FIXED    
Severity: normal CC: busybox-cvs
Priority: P5    
Version: 1.23.x   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Host: Target:
Build:

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.