bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] Gawk Handles Late-In-Command-Line -v Variable Assignments


From: arnold
Subject: Re: [bug-gawk] Gawk Handles Late-In-Command-Line -v Variable Assignments Differently When -e and -f Are Omitted
Date: Tue, 16 Apr 2019 21:58:31 -0600
User-agent: Heirloom mailx 12.5 7/5/10

Hi.

Thanks for the note.

You missed something. Try

        gawk 'BEGIN { print "a =", a
                for (i in ARGV) print i, ARGV[i] }' -v a=99

And the light should go on. :-)

Thanks,

Arnold

"Neil R. Ormos" <address@hidden> wrote:

> Hello Arnold et al.:
>
> In the examples below, only in Example 6, where
> source code is provided on the command line
> without -e, and where a variable assignment is
> provided after the source code, is the result of
> the variable assignment not available in the BEGIN
> rule.
>
> I don't know if this is intended behavior or a
> bug.  I was unable to find an explanation in the
> manual.  (If I missed something, please forgive.)
>
> The results below use Gawk 5.0.0 compiled from the
> tar achive from ftp.gnu.org, but I get the same
> results using 4.2.0 and 3.1.7 (substituting
> --source= for -e).
>
> Best regards,
>
> --Neil Ormos
>
> ################################################################################
>
> > uname -a
> Linux aloha 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64 
> GNU/Linux
>
> > lsb_release -a
> No LSB modules are available.
> Distributor ID: Debian
> Description:    Debian GNU/Linux 9.7 (stretch)
> Release:        9.7
> Codename:       stretch
>
> > gawk --version | head -1
> GNU Awk 5.0.0, API: 2.0
>
> > echo 'BEGIN{print a}' > ! test.awk
>
> > cat -n test.awk
>      1  BEGIN{print a}
>
>
> # Example 1
> >            gawk -v a=99 -f test.awk
> 99
>
> # Example 2
> >            gawk         -f test.awk         -v a=99
> 99
>
> # Example 3
> >            gawk -v a=99 -e 'BEGIN{print a}'
> 99
>
> # Example 4
> >            gawk         -e 'BEGIN{print a}' -v a=99
> 99
>
> # Example 5
> >            gawk -v a=99    'BEGIN{print a}'
> 99
>
> # Example 6
> >            gawk            'BEGIN{print a}' -v a=99
>
> # The line above was empty.
>
> ################################################################################



reply via email to

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