ThomasDickey / original-mawk

bug-reports for mawk (originally on GoogleCode)
http://invisible-island.net/mawk/mawk.html
17 stars 2 forks source link

Concatenation does not work in pipeing #35

Closed jarnos closed 7 years ago

jarnos commented 8 years ago

Instead, mawk uses the last string.

Example: printf a2 | mawk '{"printf %d 0x" $1 | getline x; print x}' gives a shell error "/bin/sh: 1: a2: not found" and does not output 162.

mawk 1.3.4 20150503

ossbsd commented 7 years ago

It works if you enclose the string concatenation within parentheses (still a bug tho):

Example: printf a2 | mawk '{ ("printf %d 0x" $1) | getline x; print x}' outputs 162

mawk 1.3.4 20150503 on FreeBSD 10.3-RELEASE-p4

mikebrennan000 commented 7 years ago

From the posix spec: The getline operator can form ambiguous constructs when there are unparenthesized operators (including concatenate) to the left of the '|' (to the beginning of the expression containing getline). In the context of the '$' operator, '|' shall behave as if it had a lower precedence than '$'. The result of evaluating other operators is unspecified, and conforming applications shall parenthesize properly all such usages.

So it is not a bug.