• One True AWK bug?

    From jeojet@jeojet@invalid.invalid to comp.lang.awk on Thu May 9 16:43:03 2024
    From Newsgroup: comp.lang.awk

    Is this a bug in original-awk, aka "The One True Awk" ?

    I noticed in this one-liner if the conditional in the print statement
    below lacks parentheses it produces and "illegal statement" error:

    --
    $ printf 'foo\n\nbar\n' |nawk '{print $0 != "" ? $0 : "[blank]"}'
    nawk: syntax error at source line 1
    context is
    {print $0 >>> != <<<
    nawk: illegal statement at source line 1
    nawk: illegal statement at source line 1
    --

    Adding parentheses OR rewriting as a match fixes things:

    --
    $ printf 'foo\n\nbar\n' |nawk '{print $0 !~ /^$/ ? $0 : "[blank]"}'
    foo
    [blank]
    bar

    $ printf 'foo\n\nbar\n' |nawk '{print ($0 != "") ? $0 : "[blank]"}'
    foo
    [blank]
    bar
    --

    Both mawk and gawk don't seem to care about lack of parentheses:

    --
    $ printf 'foo\n\nbar\n' |mawk '{print $0 != "" ? $0 : "[blank]"}'
    foo
    [blank]
    bar

    $ printf 'foo\n\nbar\n' |gawk '{print $0 != "" ? $0 : "[blank]"}'
    foo
    [blank]
    bar
    --

    Note 'nawk' here is NOT gawk, it's a more recent version of original-awk:

    $ nawk --version # from https://github.com/onetrueawk/awk
    awk version 20240122

    $ original-awk --version # version Debian apt currently has
    awk version 20220912
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From jeojet@jeojet@invalid.invalid to comp.lang.awk on Wed May 22 01:48:45 2024
    From Newsgroup: comp.lang.awk

    <snip>
    I noticed in this one-liner if the conditional in the print statement
    below lacks parentheses it produces and "illegal statement" error:

    --
    $ printf 'foo\n\nbar\n' |nawk '{print $0 != "" ? $0 : "[blank]"}'
    nawk: syntax error at source line 1
    context is
    {print $0 >>> != <<<
    nawk: illegal statement at source line 1
    nawk: illegal statement at source line 1
    --
    <snip>

    Just a followup: this got submitted as a open issue (#233) on the project
    page and there is a patch available that provides a working fix which makes nawk match mawk and gawk.

    Appologies for the original post; I wasn't aware that it's more or less
    the gawk project folks maintaining The One True Awk code and I know not
    to post gawk bugs here.

    -j
    --- Synchronet 3.20a-Linux NewsLink 1.114