bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: getline variables not global


From: Aharon Robbins
Subject: Re: getline variables not global
Date: Wed, 14 Apr 2010 23:18:24 +0300
User-agent: Heirloom mailx 12.4 7/29/08

Greetings.  Re your report:

There is no bug.  You are reading from the pipes for each input record. If
you add a

        close("echo 1")

after the first getline and 

        close("echo 2")

after the second, it will work as you expect.

What's happening is that the pipes stay open until closed by the awk
program. Since the first getline hits EOF (there is no more data coming
from the subshell) gawk does not update the variable.

Thanks for the report.

Arnold

> Summary
> A global variable is not overwritten when it is set by means of getline.
>
> OS
> Description:  Ubuntu 9.04
>
> AWK
> GNU Awk 3.1.6
>
> TC1
> echo -e '\n' | awk '{print "new line:"; "echo 1" | getline bar; print
> bar; "echo 2" | getline bar; print bar}'
> Should produce
> new line:
> 1
> 2
> new line:
> 1
> 2
> Produces currently
> new line:
> 1
> 2
> new line:
> 2
> 2
>
> TC2
> echo -e '\n' | awk '{bar="should never appear"; print "new line:"; "echo
> 1" | getline bar; print bar; "echo 2" | getline bar; print bar}'
> Should produce
> new line:
> 1
> 2
> new line:
> 1
> 2
> Produces currently
> new line:
> 1
> 2
> new line:
> should never appear
> should never appear
>
> Thanks,
> Till
>
> - --
> http://etill.net/




reply via email to

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