bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] Awk gets stucked if no filename


From: arnold
Subject: Re: [bug-gawk] Awk gets stucked if no filename
Date: Wed, 29 Nov 2017 11:28:19 -0700
User-agent: Heirloom mailx 12.4 7/29/08

Hi.

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

> address@hidden wrote:
> > Xavier Martinez Serrano <address@hidden> wrote:
>
> >> [...] If I add a pattern code but no
> >> filename to parse, awk gets stucked waiting:
>
> >> f=""
> >> $ awk '{print("hi")}'  $f
> >> ... <neverending wait>
>
> > Thank you for submitting a bug report.
>
> > Your understanding below is incorrect. When no
> > filenames are named on the command line, awk
> > reads from standard input.  This is documented
> > and has been awk's behavior ever since it
> > existed.
>
> > You can work around this in your script with
> > something like
>
> > awk '{print("hi")}'  $f /dev/null
>
> > Or be more careful to check $f before invoking awk, etc.
>
> As the manual is currently formulated, is it
> entirely fair to characterize an empty string,
> which has been provided as a command-line
> argument, as something other than a filename, so
> as to satisfy the condition "when no filenames are
> named on the command line"?

Look again:

        f=""
        awk '{print("hi")}'  $f

The expansion of $f in this instance is not the explicit
null string ("") but rather *nothing*.

        $ f=""
        $ gawk 'BEGIN { print ARGC }' "$f"
        2
        $ gawk 'BEGIN { print ARGC }' $f
        1

It it the latter case that was reported. In that case,
gawk has no command line arguments, so it reads standard input.

In any case, I will review your suggested documentation changes.

Thanks,

Arnold



reply via email to

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