Bug 59222 - grep not functioning properly in while loop
Summary: grep not functioning properly in while loop
Status: CLOSED DUPLICATE of bug 19747
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: grep (Show other bugs)
(Show other bugs)
Version: 7.2
Hardware: i686 Linux
medium
medium
Target Milestone: ---
Assignee: Bernhard Rosenkraenzer
QA Contact: Aaron Brown
URL:
Whiteboard:
Keywords:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2002-02-02 19:26 UTC by Brian Hanks
Modified: 2007-04-18 16:39 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2002-02-02 19:26:19 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

Description Brian Hanks 2002-02-02 19:26:14 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.7) Gecko/20011226

Description of problem:
The following code produces valid results from the command line but not in a
ksh,pdksh,bash,or zsh script:

#!/bin/ksh

servers_file=/tmp/servers.txt
file=/tmp/testfile.txt

cat ${servers_file} | while read server
do
  grep "${server}" ${file}
done

Include two host names in the servers.txt file.  Include two fields in the
testfile.txt, the first is a full path to any file and the second is a hostname
separated by a pipe delimiter.

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


How reproducible:
Always

Steps to Reproduce:
1.  Run the simple script and observe no result.
2.  Run from command line and observe valid results.

	

Actual Results:  It did not return valid data in the script.

Expected Results:  It should have produced the same results from both places.

Additional info:

Comment 1 Bernhard Rosenkraenzer 2002-02-25 11:22:53 UTC
grep is doing the right thing, your script isn't. 
 
You're expecting read to do things it actually doesn't, see "bug" #19747. 
 

*** This bug has been marked as a duplicate of 19747 ***

Comment 2 Brian Hanks 2002-02-25 11:38:40 UTC
Why does "read" not function the way I "expect" it to?  When I run this same
test on Solaris 7, Solaris 8, or HP-UX 11 it works exactly as I would "expect".
 Linux is the only place where I have this problem.

Comment 3 Bernhard Rosenkraenzer 2002-02-25 11:40:32 UTC
See the discussion attached to bug 19747 - your script is not standards compliant, and if 
it works, it's because your shell accepts nonstandard behavior. bash doesn't.


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