[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] POSIX mode "system" returing invalid exit status
From: |
arnold |
Subject: |
Re: [bug-gawk] POSIX mode "system" returing invalid exit status |
Date: |
Fri, 23 Mar 2018 01:07:01 -0600 |
User-agent: |
Heirloom mailx 12.4 7/29/08 |
Hi. Thanks for the note.
Steven Penny <address@hidden> wrote:
> Good:
>
> $ awk 'BEGIN {print system("grep")}'
> Usage: grep [OPTION]... PATTERN [FILE]...
> Try 'grep --help' for more information.
> 2
>
> Bad:
>
> $ awk --posix 'BEGIN {print system("grep")}'
> Usage: grep [OPTION]... PATTERN [FILE]...
> Try 'grep --help' for more information.
> 512
>
> Note that Mawk and Nawk produce the expected "2".
When gawk behaves differently with and without --posix, there is a reason.
Please see
https://www.gnu.org/software/gawk/manual/html_node/I_002fO-Functions.html#I_002fO-Functions
which describes the behavior of system() in detail. The relevant part:
Traditionally, awk's system() function has simply returned the
exit status value divided by 256. In the normal case this gives
the exit status but in the case of death-by-signal it yields a
fractional floating-point value. POSIX states that awk's system()
should return the full 16-bit value.
gawk steers a middle ground. The return values are summarized
in Table 9.5.
See the cited URL for the table.
Thanks,
Arnold