home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / unix / shell / 5335 < prev    next >
Encoding:
Text File  |  1993-01-11  |  2.2 KB  |  70 lines

  1. Newsgroups: comp.unix.shell
  2. Path: sparky!uunet!spool.mu.edu!umn.edu!noc.msc.net!news.stolaf.edu!guenther
  3. From: guenther@stolaf.edu (Philip A Guenther)
  4. Subject: Re: How to port this sh script to csh script ?
  5. In-Reply-To: menjan@cs.umb.edu's message of 11 Jan 93 04:21:59 GMT
  6. Message-ID: <GUENTHER.93Jan11000533@amcl5.stolaf.edu>
  7. Lines: 55
  8. Sender: news@news.stolaf.edu
  9. Organization: Academic Computing Center, St. Olaf College
  10. References: <MENJAN.93Jan10232159@ra.cs.umb.edu>
  11. Distribution: usa
  12. Date: Mon, 11 Jan 1993 06:05:37 GMT
  13. Lines: 55
  14.  
  15.    Two questions for csh experts :
  16.  
  17.    1. How to port this sh script to csh script ?
  18.  
  19. "Luke, Don't give in to the csh side of shell programming!"
  20.  
  21.    #!/bin/sh
  22.    while read line_by_line 
  23.    do
  24.        echo "Do something for $line_by_line"
  25.    done < input_file
  26.  
  27.    2. Can I use "line" command in my previous example csh script ?
  28.       If answer is 'Yes', then How ?
  29.  
  30. Yes, but it's tricky.  I'm inclined to tell you "No" just because it's
  31. so bad, but here's a way.... (Not for the quesy stomached)
  32.  
  33. #!/bin/csh
  34. set t1 = /tmp/1tmp$$
  35. set t2 = /tmp/2tmp$$
  36. set t3 = /tmp/3tmp$$
  37. set t4 = /tmp/4tmp$$
  38. cp input_file $t1
  39. echo 0 >$t2
  40. while ( `cat $t2` )
  41.   (line > $t3; echo $status > $t2; cat > $t4) < $t1
  42.   mv $t4 $t1
  43.   set line_by_line = `cat $t3`
  44.   echo "Do something for $line_by_line"
  45. end
  46.  
  47. The first temp file holds the not yet read stuff, the second holds the
  48. exit status of the line command, the third the output of the line
  49. command, and the forth is the stuff not yet read while we read the
  50. first line of the first temp.  Wheew!
  51.  
  52.   Now while I'm sure some of that could be made nicer, it still
  53. doesn't hide the fact that the Bourne shell version is cleaner,
  54. *clearer*, nicer, faster, able to work on systems that don't have csh
  55. (not all do you know!), etc, etc.  So the *real* answer to your
  56. question is "Yes, but you don't want to."  Can you explain why you
  57. would *want* to?
  58.  
  59.    Thank you very much.
  60.    -Jane
  61.  
  62. You're welcome (I think)
  63.  
  64. Philip Guenther
  65. --
  66. guenther@stolaf.edu (Philip Guenther)       | The ACC might agree with me,
  67. Student Sys Prog, Academic Computing Center | but with that bunch, (and me)
  68. St Olaf College, Northfield, MN 55057       | you never know... :-| :-( :-)
  69. "Life makes sense?  LIFE MAKES SENSE!?!?  Where do people get these ideas?"
  70.