bug-gawk
[Top][All Lists]
Advanced

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

mawk vs gawk: match() difference -- bug? (correct version)


From: Richard
Subject: mawk vs gawk: match() difference -- bug? (correct version)
Date: Wed, 30 Dec 2020 14:01:57 -0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0

        Find below the difference between gawk and mawk regardinng the match()
built-in function: mawk reacts as expected whilst gawk does not. Hence
the question: is it a bug?

<quote>
$ cat test.awk
        BEGIN {
                str = "`abcdefghijklmnopqrstuvwxyz` # rest of string"
                pat = "^\\`[^\\`]*(\\`|\\\\$)"
                pos = match(str,  pat)
                print "str = \"" str "\""
                print "pat = \"" pat "\""
                print "pos = " pos
                print "RSTART = " RSTART
                print "RLENGTH = " RLENGTH
                print "substr = \"" substr(str, RSTART, RLENGTH) "\""
              }

$ sudo update-alternatives --config awk
        There are 2 choices for the alternative awk (providing /usr/bin/awk).

          Selection    Path            Priority   Status
        ------------------------------------------------------------
          0            /usr/bin/gawk    10        auto mode
          1            /usr/bin/gawk    10        manual mode
        * 2            /usr/bin/mawk    5         manual mode

        Press <enter> to keep the current choice[*], or type selection number: 1
        update-alternatives: using /usr/bin/gawk to provide /usr/bin/awk (awk)
in manual mode

$ awk -Wv
        GNU Awk 4.1.3, API: 1.1 (GNU MPFR 3.1.4, GNU MP 6.1.0)
        Copyright (C) 1989, 1991-2015 Free Software Foundation.

        This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 3 of the License, or
        (at your option) any later version.

        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.

        You should have received a copy of the GNU General Public License
        along with this program. If not, see http://www.gnu.org/licenses/.

$ awk -f test.awk
        str = "`abcdefghijklmnopqrstuvwxyz` # rest of string"
        pat = "^\`[^\`]*(\`|\\$)"
        pos = 1
        RSTART = 1
        RLENGTH = 0
        substr = ""

$ sudo update-alternatives --config awk
        There are 2 choices for the alternative awk (providing /usr/bin/awk).

          Selection    Path            Priority   Status
        ------------------------------------------------------------
          0            /usr/bin/gawk    10        auto mode
        * 1            /usr/bin/gawk    10        manual mode
          2            /usr/bin/mawk    5         manual mode

        Press <enter> to keep the current choice[*], or type selection number: 2
        update-alternatives: using /usr/bin/mawk to provide /usr/bin/awk (awk)
in manual mode
$ awk -Wv
        mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan

        compiled limits:
        max NF             32767
        sprintf buffer      2040

$ awk -f test.awk
        str = "`abcdefghijklmnopqrstuvwxyz` # rest of string"
        pat = "^\`[^\`]*(\`|\\$)"
        pos = 1
        RSTART = 1
        RLENGTH = 28
        substr = "`abcdefghijklmnopqrstuvwxyz`"
</quote>



reply via email to

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