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

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

Re: possible gawk bug: 3.1.1 getline vs. 3.1.5 getline


From: Aharon Robbins
Subject: Re: possible gawk bug: 3.1.1 getline vs. 3.1.5 getline
Date: Fri, 03 Apr 2009 11:18:41 +0300

Hi. Thanks for the note.

This is fixed in gawk 3.1.6. Please upgrade.

In any case, as there are different awk implementations that do different
things, it is best to parenthesize concatenations on the left of a getline:

        ("xxx" "yyy" "zzz") | getline

Thanks,

Arnold

> Date: Tue, 31 Mar 2009 16:22:17 -0700
> From: "Alford, Seth" <address@hidden>
> To: address@hidden
> Cc: address@hidden
> Subject: possible gawk bug: 3.1.1 getline vs. 3.1.5 getline
>
> Consider the following awk script:
> ----beginning of script----
> #!/bin/sh
>
> echo "from the regular file" > /tmp/regular
> echo "input file line" > /tmp/input
> awk ' BEGIN {
> regular_basename="regular"
> }
> {
> printf "Before getline, dollar 0 is:\n%s\n", $0 
> printf "And the regular_basename is:\n%s\n", regular_basename
> }
> {
> "ls -lsdk /tmp/"regular_basename" 2> /dev/null" | getline
> printf "ls -lsdk /tmp/\"regular_basename\" 2> /dev/null | getline; and dollar 
> 0 is:\n%s\n", $0
> close("ls -lsdk /tmp/"regular_basename" 2> /dev/null")
> } ' /tmp/input
> ----end of script----
>
> I have a system which is based on RedHat Linux 8.0 (RH8.0 rpm's
> with a newer kernel.)  gawk --version says:
>
> GNU Awk 3.1.1
>
> I have another system based on CentOS 5.2.  gawk --version says:
>
> GNU Awk 3.1.5
>
> On gawk 3.1.1 on almost-RH 8.0, I get:
>
> ----start of cut and paste from RH 8.0 shell session----
> address@hidden setha]# ./awktest
> Before getline, dollar 0 is:
> input file line
> And the regular_basename is:
> regular
> ls -lsdk /tmp/"regular_basename" 2> /dev/null | getline; and dollar 0 is:
>    4 -rw-r--r--    1 setha    se             22 Mar 31 15:31 /tmp/regular
> address@hidden setha]# 
> ----end of cut and paste from RH 8.0 shell session----
>
> On gawk 3.1.5 on almost-CentOS 5.2, I get:
>
> ----start of cut and paste from CentOS 5.2 shell session----
> address@hidden tmp]# ./awktest
> Before getline, dollar 0 is:
> input file line
> And the regular_basename is:
> regular
> ls -lsdk /tmp/"regular_basename" 2> /dev/null | getline; and dollar 0 is:
> input file line
> address@hidden tmp]# 
> ----end of cut and paste from CentOS 5.2 shell session----
>
> The output is not the same.  I ran it as root in both cases, so I
> don't think that permissions are a problem.  The later gawk
> apparently does not like the 
>
>       "... /tmp/"regular_basename
>
> construct.  
>
> A workaround is to construct the string that gets fed to getline,
> separately:
>
> ----start of script with workaround---
> #!/bin/sh
>
> echo "from the regular file" > /tmp/regular
> echo "input file line" > /tmp/input
> awk ' BEGIN {
> regular_basename="regular"
> }
> {
> printf "Before getline, dollar 0 is:\n%s\n", $0 
> printf "And the regular_basename is:\n%s\n", regular_basename
> }
> {
> getline_string=sprintf("ls -lsdk /tmp/%s 2> /dev/null", regular_basename)
>
> getline_string | getline
> printf "getline_string piped into getline, ie:\n%s | getline\n", 
> getline_string
> printf "dollar 0:\n%s\n", $0
> close(getline_string)
> } ' /tmp/input
> ----end of workaround version of script----
>
> This version works the same on both version of gawk.  Here's
> the output:
>
> ----begin cut & paste----
> address@hidden tmp]# ./awktest5
> Before getline, dollar 0 is:
> input file line
> And the regular_basename is:
> regular
> getline_string piped into getline, ie:
> ls -lsdk /tmp/regular 2> /dev/null | getline
> dollar 0:
> 4 -rw-r--r-- 1 root root 1 Mar 31 16:11 /tmp/regular
> address@hidden tmp]# 
> ----end of cut & paste----
>
> I think that gawk 3.1.5 should run the script the way gawk 3.1.1
> does, without the workaround.
>
> --Seth




reply via email to

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