[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] Awk gets stucked if no filename
From: |
Arnold Robbins |
Subject: |
Re: [bug-gawk] Awk gets stucked if no filename |
Date: |
Thu, 21 Jun 2018 21:00:46 +0300 |
User-agent: |
Heirloom mailx 12.5 6/20/10 |
Hi.
I am going through old mail. I may never have answered
this, I don't remember.
See below.
> Date: Wed, 29 Nov 2017 11:59:07 -0600 (CST)
> From: "Neil R. Ormos" <address@hidden>
> To: Bug Gawk Mailing List <address@hidden>
> cc: "Arnold D. Robbins/gawk Developer" <address@hidden>
> Subject: Re: [bug-gawk] Awk gets stucked if no filename
>
> 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"?
In the case under discussion:
f=""
awk '{ print("hi") }' $f
awk doesn't see an explicit empty string. When a variable
expansion is the null string, AND it's not quoted, the
shell simply removes it from the command line. To demonstrate:
$ f=""
$ awk 'BEGIN { print ARGC }' $f
1
$ awk 'BEGIN { print ARGC }' "$f"
2
Hope this helps.
Thanks,
Arnold
- Re: [bug-gawk] Awk gets stucked if no filename,
Arnold Robbins <=