[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] BEGINFILE/ENDFILE bug?
From: |
Andrew J. Schorr |
Subject: |
Re: [bug-gawk] BEGINFILE/ENDFILE bug? |
Date: |
Sat, 17 May 2014 17:44:23 -0400 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Sat, May 17, 2014 at 01:59:35PM -0500, Ed Morton wrote:
> So, despite what the error message says ( `getline' invalid inside
> `ENDFILE'), you CAN use a redirected getline in ENDFILE (and
> BEGINFILE) but only if using it to populate a variable rather than
> $0. END, on the other hand, lets you do either.
This behavior is actually documented:
The `getline' statement (*note Getline::) is restricted inside both
`BEGINFILE' and `ENDFILE'. Only the `getline VARIABLE < FILE' form is
allowed.
> It's not obvious why ENDFILE would require a variable to populate
> when END doesn't, and I think that error message is misleading. A
> better error message might be something like:
It is not obvious to me either, but I'm guessing that there's a good
reason. The attached patch seems to enable `getline < file', but I may
well be missing something.
Also, the documentation above doesn't seem quite right. For example, I think
this already works:
bash-4.2$ gawk 'BEGINFILE { "cat /etc/passwd" | getline; print}' /dev/null
root:x:0:0:root:/root:/bin/bash
Perhaps it should say that only redirected forms of getline are allowed.
I don't see why the previous example should work, whereas this doesn't:
bash-4.2$ gawk 'BEGINFILE { getline < "/etc/passwd"; print}' /dev/null
gawk: cmd. line:1: error: `getline' invalid inside `BEGINFILE' rule
With the attached patch, these both work as expected.
Regards,
Andy
getline.patch
Description: Text document
- [bug-gawk] ENDFILE bug?, Ed Morton, 2014/05/17
- Re: [bug-gawk] BEGINFILE/ENDFILE bug?,
Andrew J. Schorr <=
- Re: [bug-gawk] BEGINFILE/ENDFILE bug?, Ed Morton, 2014/05/18
- Re: [bug-gawk] BEGINFILE/ENDFILE bug?, Andrew J. Schorr, 2014/05/18
- Re: [bug-gawk] BEGINFILE/ENDFILE bug?, Ed Morton, 2014/05/18
- Re: [bug-gawk] BEGINFILE/ENDFILE bug?, Aharon Robbins, 2014/05/19
- Re: [bug-gawk] BEGINFILE/ENDFILE bug?, Aharon Robbins, 2014/05/21
- Re: [bug-gawk] BEGINFILE/ENDFILE bug?, Ed Morton, 2014/05/22