Redirecting stdin in CSH

Redirecting stdin in CSH

Post by juk.. » Wed, 07 Nov 1990 08:50:58



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         |

+---------------------------------------------------------+