Subject: Re: problem with NetBSD awk
To: None <>
From: None <>
List: tech-userlevel
Date: 04/22/2006 20:17:00

On Sat, Apr 22, 2006 at 08:47:24PM +0300, Aleksey Cheusov wrote:
> Hi all.
> Can anybody explain me this?
> 0 ~>/usr/pkg/bin/gawk -v nls="`printf 'a\nb\n'`" 'BEGIN { print nls }'
> a
> b
> 0 ~>/usr/pkg/bin/mawk -v nls="`printf 'a\nb\n'`" 'BEGIN { print nls }'
> a
> b
> 0 ~>/usr/bin/awk -v nls="`printf 'a\nb\n'`" 'BEGIN { print nls }'
> /usr/bin/awk: newline in string a
> b... at source line 1
> 2 ~>
> All three awk implementation works the same way with the following command
> /usr/bin/awk -v nls='a\nb\n' 'BEGIN { print nls }'
> susv3 says the following

The fact that the second version works is normal, since in susv3 (IMHO
you didn't quote the relevant part :

The token STRING shall represent a string constant. A string constant
shall begin with the character ' .' Within a string constant, a
backslash character shall be considered to begin an escape sequence as
specified in the table in the Base Definitions volume of IEEE Std
1003.1-2001, Chapter 5, File Format Notation ( '\\' , '\a' , '\b' , '\f'
, '\n' , '\r' , '\t' , '\v' ). In addition, the escape sequences in
Expressions in Decreasing Precedence in awk shall be recognized. A
<newline> shall not occur within a string constant.[...]
----end quote

A litteral shall not appear in a STRING. The printf(1) includes a
litteral one in the string, while the "-v nls='a\nb\n'" passes a correct
STRING with escaped sequences.

So, regarding NetBSD version of awk (nawk), it is posix compliant one
(regarding this) while others seem not.

Thierry Laronde (Alceste) <tlaronde +AT+ polynum +dot+ com>
Key fingerprint = 0FF7 E906 FBAF FE95 FD89  250D 52B1 AE95 6006 F40C