How to port this sh script to csh script ?

How to port this sh script to csh script ?

Post by Men-Jan L » Tue, 12 Jan 1993 13:21:59



Two questions for csh experts :

1. How to port this sh script to csh script ?

#!/bin/sh
while read line_by_line
do
        echo "Do something for $line_by_line"
done < input_file

2. Can I use "line" command in my previous example csh script ?
   If answer is 'Yes', then How ?

Thank you very much.

-Jane

PS: What I want is processing input_file line by line.

 
 
 

How to port this sh script to csh script ?

Post by Philip A Guenth » Tue, 12 Jan 1993 15:05:37


   Two questions for csh experts :

   1. How to port this sh script to csh script ?

"Luke, Don't give in to the csh side of shell programming!"

   #!/bin/sh
   while read line_by_line
   do
           echo "Do something for $line_by_line"
   done < input_file

   2. Can I use "line" command in my previous example csh script ?
      If answer is 'Yes', then How ?

Yes, but it's tricky.  I'm inclined to tell you "No" just because it's
so bad, but here's a way.... (Not for the quesy stomached)

#!/bin/csh
set t1 = /tmp/1tmp$$
set t2 = /tmp/2tmp$$
set t3 = /tmp/3tmp$$
set t4 = /tmp/4tmp$$
cp input_file $t1
echo 0 >$t2
while ( `cat $t2` )
  (line > $t3; echo $status > $t2; cat > $t4) < $t1
  mv $t4 $t1
  set line_by_line = `cat $t3`
  echo "Do something for $line_by_line"
end

The first temp file holds the not yet read stuff, the second holds the
exit status of the line command, the third the output of the line
command, and the forth is the stuff not yet read while we read the
first line of the first temp.  Wheew!

  Now while I'm sure some of that could be made nicer, it still
doesn't hide the fact that the Bourne shell version is cleaner,
*clearer*, nicer, faster, able to work on systems that don't have csh
(not all do you know!), etc, etc.  So the *real* answer to your
question is "Yes, but you don't want to."  Can you explain why you
would *want* to?

   Thank you very much.
   -Jane

You're welcome (I think)

Philip Guenther
--

Student Sys Prog, Academic Computing Center | but with that bunch, (and me)
St Olaf College, Northfield, MN 55057       | you never know... :-| :-( :-)
"Life makes sense?  LIFE MAKES SENSE!?!?  Where do people get these ideas?"