bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] What is wrong with getline from both stdin and a file fro


From: Peng Yu
Subject: Re: [bug-gawk] What is wrong with getline from both stdin and a file from ARGV?
Date: Wed, 28 Nov 2018 19:51:28 -0600

> The problem with your second command, as I already explained, is that it opens
> the file twice: the first time because it's supplied on the command-line as a
> source of data, and the second time because you explicitly accessed it by
> calling "getline < ARGV[1]".

I am not sure this explanation makes sense.

Why the first getline in the following example read from /dev/fd/63?
It is to read from stdin, shouldn't it be different from ARGV[1]?

$ printf '%s\n' 1 2 3 | awk -e 'BEGIN { getline; print getline <
ARGV[1]; print  }' <(printf '%s\n' {a..c})
0
a
awk: (FILENAME=/dev/fd/63 FNR=1) warning: close of fd 63
(`/dev/fd/63') failed (Bad file descriptor)

Also, the following code works just fine. It would be strange to be
able to read ARGV[2] but not ARGV[1]
$ printf '%s\n' 1 2 3 | awk -e 'BEGIN { getline; print getline <
ARGV[2]; print  }' <(printf '%s\n' {a..c})  <(printf '%s\n' {A..C})
1
A

-- 
Regards,
Peng



reply via email to

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