Subject: Re: problem with NetBSD awk
To: None <tech-userlevel@NetBSD.org>
From: Jaromir Dolecek <jdolecek@NetBSD.org>
List: tech-userlevel
Date: 04/22/2006 21:11:45
--r5Pyd7+fXNt84Ff3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sat, Apr 22, 2006 at 09:42:27PM +0300, Aleksey Cheusov wrote:
>  >> 0 ~>/usr/bin/awk -v nls=3D"`printf 'a\nb\n'`" 'BEGIN { print nls }'
>  >> /usr/bin/awk: newline in string a
>  >> b... at source line 1
>  >> 2 ~>
>  >>=20
>  >> All three awk implementation works the same way with the following co=
mmand
>  >> /usr/bin/awk -v nls=3D'a\nb\n' 'BEGIN { print nls }'
>  >>=20
>  >> susv3 says the following
>=20
> > The fact that the second version works is normal,
> Agree. This case is just easier to explain ;)
>=20
> > since in susv3 (IMHO
> > you didn't quote the relevant part :
> My quote was correct but incomplete.
> My question was _NOT_ about -v a=3D"a\nb\n"
>=20
> > So, regarding NetBSD version of awk (nawk), it is posix compliant one
> > (regarding this) while others seem not.
> Very strange conslusion.

susv3 appears to say the string cannot contain unescaped newline
character. When using awk -v "`printf 'a\n'`" you are doing exactly
that (passing unescaped newline in string).

What nawk appears to be doing is that it handles -v nls=3Dfoo
~same as BEGIN { nls =3D "foo" }. Try:

gawk 'BEGIN { nls =3D "'"`printf 'a\nb'`"'}'

That gives error. The difference is that nawk uses same
rule for -v, while gawk and mawk handles -v assignment
differently.

So I'd say awk (actually nawk) behaviour is just fine and
in-line with the standard.

Jaromir
--=20
Jaromir Dolecek <jdolecek@NetBSD.org>            http://www.NetBSD.cz/
-=3D- We can walk our road together if our goals are all the same;     -=3D-
-=3D- We can run alone and free if we pursue a different aim.          -=3D-

--r5Pyd7+fXNt84Ff3
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 5.0i for non-commercial use
MessageID: ryhtQ4dT3VcrnLSPA3i/d6gm5ff32Q6o

iQCVAwUBREp/8LZjOQfIPRaZAQGHRQP/QmHu4s5KrqeYyLtYVLMbaF8ledvD0dHt
tDR1P4pIQGPuaGXDBLecNAFyt3tJE4+wMwIzmghbgSuiFdu584xlc4bGAPP7ZrEg
dhWEuIzNLz6xf+kUDh7Y5C6jFpsKp0nF9W33c3jXcvECQ33lZ6GI4IQNegjWQwJ8
v6p9jSETsPU=
=wxtz
-----END PGP SIGNATURE-----

--r5Pyd7+fXNt84Ff3--