|
From: | Ed Morton |
Subject: | Re: no exit status available when a command doesn't exist or fails in pipe to grep |
Date: | Thu, 9 Sep 2021 10:52:57 -0500 |
User-agent: | Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 |
On 9/9/2021 10:15 AM, Neil R. Ormos wrote:
Ed Morton wrote:arnold@skeeve.com wrote:"Andrew J. Schorr" <aschorr@telemetry-investments.com> wrote:So gawk forces the return code to 0 in POSIX mode in almost all cases.[...] And as I pointed out earlier, different awks do different things anyway, so there's no reliable portable way to deal with the status from close().That's fine of course but why not just do in POSIX mode the same thing that gawk does in non-POSIX mode since it'd apparently still be POSIX compliant either way and would be more useful?How would that be compliant with the POSIX requirement that | If the close was successful, the | function shall return zero; otherwise, | it shall return non-zero. ... ? How does a return code from the command used with the pipeline affect whether the close() was successful?
It depends what "successful" means. Imagine you try to close a door that was never opened:
a) if "success" means the door is closed then the result is "success",b) If "success" means the action you took caused the door to close then the result is "failure"
Since POSIX doesn't define "succesful" in the context of calling close() it can mean whichever we want it to mean and in the above example I'd hope we'd go with "b" and get results from calling close() like:
0 (success) = the action we took caused the command to close, orN (failure) = or our attempt to close it failed for reason N (which includes why it was already closed if that was the case)
since that would be much more useful than just 0 if the command is closed or N if our attempt to close it failed and lose the information about why it was already closed before we tried to close it if that was the case.
Regards, Ed.
Wouldn't close() be successful if it has its usual effect? Does a return code from the command prevent close() from releasing any OS or gawk-internal resources? If, after the close(), something new is piped to the identical command string (or whatever it's called), does gawk treat the pipeline as it would had close() not been called, or does it build a new one and invoke the command(s) anew?
[Prev in Thread] | Current Thread | [Next in Thread] |