bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: no exit status available when a command doesn't exist or fails in pi


From: arnold
Subject: Re: no exit status available when a command doesn't exist or fails in pipe to grep
Date: Thu, 09 Sep 2021 01:58:59 -0600
User-agent: Heirloom mailx 12.5 7/5/10

Ed Morton <mortoneccc@comcast.net> wrote:

> I know this is a gawk mailing list but I don't suppose you know of a 
> POSIX equivalent?
>
>     $ awk --posix 'BEGIN{cmd="garbage"; (cmd | getline); print close(cmd)}'
>     sh: garbage: command not found
>     0

POSIX merely says that 

| close(expression)
|     Close the file or pipe opened by a print or printf statement or a
|     call to getline with the same string-valued expression. The limit on
|     the number of open expression arguments is implementation-defined. If
|     the close was successful, the function shall return zero; otherwise,
|     it shall return non-zero.

This is fairly vague.  I think you're getting zero because the
underlying pclose() (or equivalent code) succeeds, even thogh the
command itself failed.

Different awks do different things here:

$ mawk 'BEGIN{cmd="garbage"; (cmd | getline); print close(cmd)}'
/bin/sh: 1: garbage: not found
127

$ nawk 'BEGIN{cmd="garbage"; (cmd | getline); print close(cmd)}'
sh: 1: garbage: not found
0

I think you're just SOL on this one.

Arnold



reply via email to

[Prev in Thread] Current Thread [Next in Thread]