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:
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 ***
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.
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.