Hi,

from what I understand of:

http://pubs.opengroup.org/onlinepubs/9699919799.2016edition/utilities/awk.html
awk's grammar.

echo x file | awk '{print $1 > $2 ".txt"}'

is meant to write "x\n" to "file.txt"

And:

awk 'BEGIN{print 1 > 2 > 3}'

is meant to be the same as:

awk 'BEGIN{print 1 > (2 > 3)}'

The text does mentions the ambiguities of getline or of "/"
versus "/ERE/", but there's no mention of the ambiguity of the
">"/">>" redirection operators and the ">"/">>" comparison/shift
operators.

The grammar does take a lot of care making sure ">"/">>"
comparison/shift operators are not ones of the operators allowed
to be left bare in the <print_expr_list_opt> in

"print" <print_expr_list_opt> ">"/">>"/"|" <expr>

Still:

echo x file | awk '{print $1 > $2 ".txt"}'

gives an error in most awk implementations based on the original
nawk including the ones on BSDs and bwk's (not the original awk
on Unix V7 from the 70s), though it looks like it was fixed in
/usr/xpg4/bin/awk on Solaris.

awk 'BEGIN{print 1 > 2 > 3}'

still gives an error even in /usr/xpg4/bin/awk on Solaris and
gawk.

AFAICT, only mawk and busybox awk are compliant in that regard.

Should that be regarded as bugs in those implementations or
should the grammar be changed?

The grammar changed radically on that front between the 70s awk
and nawk. I'm not sure why. There's a lot of things in nawk that
are no longer allowed on the right side of the ">"/">>"/"|"
redirection operators. I can't see the justification for that.

-- 
Stephane

Reply via email to