Ed Morton
2023-05-25 14:30:53 UTC
I'm certain I remember years ago reading a document that said
(paraphrasing) "an unparenthesized expression on the right side of input
or output redirection is undefined behavior" and I thought it was an
older version of the POSIX spec. I now can't find that (or similar)
statement in any of these:
SUSV2 - https://pubs.opengroup.org/onlinepubs/7990989775/xcu/awk.html
SUSV3 -
https://pubs.opengroup.org/onlinepubs/009695399/utilities/awk.html
Current POSIX spec -
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html
or by googling.
What I do see in the current POSIX spec is a related statement just
conventional parsing), the meaning of these constructs has been made
explicitly unspecified.
the '<' (up to the end of the expression containing the getline). The
result of evaluating such a construct is unspecified
but nothing about output redirection. I know gawk doesn't require parens
around the expression for output redirection but other awks do (e.g. see
https://stackoverflow.com/q/21093626/1745001) and it's not obvious to me
why `getline < "a" "b"` should be undefined behavior while `print > "a"
"b"` wouldn't be so intuitively if one of them is undefined then so
should the other be.
Does anyone else recall seeing a statement about output redirection to
an expression requiring parens and, if so, do you recall where it existed?
Ed.
(paraphrasing) "an unparenthesized expression on the right side of input
or output redirection is undefined behavior" and I thought it was an
older version of the POSIX spec. I now can't find that (or similar)
statement in any of these:
SUSV2 - https://pubs.opengroup.org/onlinepubs/7990989775/xcu/awk.html
SUSV3 -
https://pubs.opengroup.org/onlinepubs/009695399/utilities/awk.html
Current POSIX spec -
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html
or by googling.
What I do see in the current POSIX spec is a related statement just
getline < "a" "b"
( getline < "a" ) "b"
although many would argue that the intent was that the file ab should
getline < "x" + 1
getline < ( "x" + 1 )
...
Since in most cases such constructs are not (or at least should not)
be used (because they have a natural ambiguity for which there is no( getline < "a" ) "b"
although many would argue that the intent was that the file ab should
getline < "x" + 1
getline < ( "x" + 1 )
...
Since in most cases such constructs are not (or at least should not)
conventional parsing), the meaning of these constructs has been made
explicitly unspecified.
The getline operator can form ambiguous constructs when there are
unparenthesized binary operators (including concatenate) to the right ofthe '<' (up to the end of the expression containing the getline). The
result of evaluating such a construct is unspecified
but nothing about output redirection. I know gawk doesn't require parens
around the expression for output redirection but other awks do (e.g. see
https://stackoverflow.com/q/21093626/1745001) and it's not obvious to me
why `getline < "a" "b"` should be undefined behavior while `print > "a"
"b"` wouldn't be so intuitively if one of them is undefined then so
should the other be.
Does anyone else recall seeing a statement about output redirection to
an expression requiring parens and, if so, do you recall where it existed?
Ed.