Bug 59222 - grep not functioning properly in while loop
grep not functioning properly in while loop
Status: CLOSED DUPLICATE of bug 19747
Product: Red Hat Linux
Classification: Retired
Component: grep (Show other bugs)
7.2
i686 Linux
medium Severity medium
: ---
: ---
Assigned To: Bernhard Rosenkraenzer
Aaron Brown
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2002-02-02 14:26 EST by Brian Hanks
Modified: 2007-04-18 12:39 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2002-02-02 14:26:19 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 Brian Hanks 2002-02-02 14:26:14 EST
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 06:22:53 EST
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 06:38:40 EST
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 06:40:32 EST
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.