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

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

possible gawk bug: 3.1.1 getline vs. 3.1.5 getline


From: Alford, Seth
Subject: possible gawk bug: 3.1.1 getline vs. 3.1.5 getline
Date: Tue, 31 Mar 2009 16:22:17 -0700
User-agent: Mutt/1.5.18 (2008-05-17)

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


This message and any attachments are intended only for the use of the addressee 
and may contain information that is privileged and confidential. If the reader 
of the message is not the intended recipient or an authorized representative of 
the intended recipient, you are hereby notified that any dissemination of this 
communication is strictly prohibited. If you have received this communication 
in error, please notify us immediately by e-mail and delete the message and any 
attachments from your system.




reply via email to

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