Redirecting stdin in CSH

jukoff at parc.xerox.com jukoff at parc.xerox.com
Tue Nov 6 10:50:58 AEST 1990


How do I redirect stdin in a Csh script?  For example, a simple "cat" command.

Here is the equivalent code in Bourne sh:

#!/bin/sh
exec 9<&0 < /etc/passwd			# Input any file here 
while read line
do
        echo $line...
done
exec 0<&9 9<&-

-----------------------------------------------------------------
It's very easy in Perl:

#!/usr/local/bin/perl

while (<>) { print ; }

-----------------------------------------------------------------
But I'm stumped in Csh.  For example, this doesn't work (the Csh converts
newlines to spaces on input -AND- foreach is space-delimited):
#!/bin/csh

foreach line (`cat /etc/passwd`)
        echo $line...
end

+---------------------------------------------------------+
| Steven Jukoff,             Phone: (415)494-4316         |
| Xerox PARC                 DDN:   jukoff at parc.xerox.com |
+---------------------------------------------------------+



More information about the Comp.unix.questions mailing list