Bug 450172 - Gawk 3.1.3 while bug
Gawk 3.1.3 while bug
Status: CLOSED NOTABUG
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: gawk (Show other bugs)
4.6
All Linux
low Severity medium
: rc
: ---
Assigned To: Jan Zeleny
Brock Organ
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2008-06-05 13:25 EDT by Christopher
Modified: 2010-03-05 11:47 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2010-03-05 11:47:57 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Christopher 2008-06-05 13:25:01 EDT
Description of problem:
In Gawk version 3.1.3 strings can not be expanded within a while loop.

Version-Release number of selected component (if applicable):
3.1.3

How reproducible:
Always

Steps to Reproduce:
1. Create a simple awk script. For example:
#!/usr/bin/gawk -f
# test.gawk
BEGIN {
   comm="-al";
   while("/bin/ls "comm | getline >0){
      print 
   }
}
2. Run the script. ./test.gawk
  
Actual results:
garbage

Expected results:
listing of what's in my run directory

Additional info:
This works for any string in the while loop with variables.
For example comm="w"; while( "ps -e" comm "f" | getline >0){ also does not work.
An easy fix is to resolve the string before the loop, for example:
joe="ps -e" comm "f"
while( joe | getline >0){

This works fine in RedHat Enterprise 3.8 with Gawk 3.1.1

-Chris
Comment 1 Didar Hossain 2008-07-30 07:22:10 EDT
Use parentheses around the string concatenation to get this working. Not
using parentheses makes the expression ambiguous.

Reference:
htte://www.gnu.org/manual/gawk/html_node/Getline_002fPipe.html#Getline_002fPipe
Comment 2 Didar Hossain 2008-07-31 16:31:02 EDT
Here is the right way to do it with the original script -

#!/usr/bin/gawk -f
# test.gawk
BEGIN {
   comm="-al";
   while(("/bin/ls "comm) | getline >0){
      print 
   }
}

Notice the parentheses in the expression in the "while" condition.

- Didar
Comment 3 Jan Zeleny 2010-03-05 11:47:57 EST
Since this has been already solved in previous comments, I'm closing this as NOTABUG.

Note You need to log in before you can comment on or make changes to this bug.