Subject: Re: awk regression
To: None <tech-userlevel@NetBSD.org>
From: None <tlaronde@polynum.com>
List: tech-userlevel
Date: 04/16/2007 12:35:01
Hello,
On Mon, Apr 16, 2007 at 09:07:48AM +0000, Emmanuel Dreyfus wrote:
> Hello
>
> I burnt myself hot when upgrading a pre NetBSD 2 box because awk regressed.
> This caused chaos in a few administrative shell scripts.
>
> Here is the problem:
>
> # Works on 2.x, not on 3.x
> awk -vf=x 'BEGIN {print f}' /dev/null
> # Works on any release
> awk -v f=x 'BEGIN {print f}' /dev/null
>
> The problem is rather old, but it's not a reason for not handling it.
> Did someone give it a try in the past?
SUSv3, XBD 12.1 Utility Argument syntax:
Guideline 6:
Each option and option-argument should be a separate argument,
except as noted in Utility Argument Syntax , item (2).
and Utility Argument Syntax item(2) is:
Option-arguments are sometimes shown separated from their options by
<blank>s, sometimes directly adjacent. This reflects the situation that
in some cases an option-argument is included within the same argument
string as the option; in most cases it is the next argument. The Utility
Syntax Guidelines in Utility Syntax Guidelines require that the option
be a separate argument from its option-argument, but there are some
exceptions in IEEE Std 1003.1-2001 to ensure continued operation of
historical applications:
a. If the SYNOPSIS of a standard utility shows a <space> between
an option and option-argument (as with [ -c option_argument] in
the example), a conforming application shall use separate
arguments for that option and its option-argument.
b.If a <space> is not shown (as with [ -foption_argument]
in the example), a conforming application shall place an
option and its option-argument
directly adjacent in the same argument string, without
intervening <blank>s.
c.Notwithstanding the preceding requirements on
conforming applications, a conforming implementation
shall permit an application to specify options and
option-arguments as a single argument or as separate
arguments whether or not a <space> is shown on the
synopsis line, [XSI] [Option Start] except in those
cases (marked with the XSI portability warning) where
an option-argument is optional and no separation can be
used. [Option End]
d. A standard utility may also be implemented to operate
correctly when the required separation into multiple
arguments is violated by a non-conforming application.
So, if I understand correctly, awk(1) is not required to treat the
option/option-argument as a single argument (the may in 4.). The 2c here
is a bit fuzzy to many, but IIUC it applies to other applications than
standard utilities (XSI extensions?).
Cheers,
--
Thierry Laronde (Alceste) <tlaronde +AT+ polynum +dot+ com>
http://www.kergis.com/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89 250D 52B1 AE95 6006 F40C