Closed juster closed 1 year ago
Interesting! Linking the GAWK docs on this for reference. For comparison, POSIX just says "If the close was successful, the function shall return zero; otherwise, it shall return non-zero."
Ah nice! Those linked docs explain plan9 awk's behavior:
In many older versions of Unix awk, the close() function is actually a statement. (d.c.) It is a syntax error to try and use the return value from close():
It complains about an illegal statement.
But yeah this is definitely an undocumented easter egg!
An undocumented feature of other awks is to have the
close()
builtin function return the exit status of the process which was opened by the pipe. Theclose()
builtin for goawk always returns -1 for output pipes and always returns 0 for input pipes.Example
Portability?
Different awks also have various implementations. The same example above was run for ...
edit: Removed duplicate rows. I also remembered how the
wait()
result shifts the exit code.