Closed jarnos closed 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
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.
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