home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.shell
- Path: sparky!uunet!spool.mu.edu!umn.edu!noc.msc.net!news.stolaf.edu!guenther
- From: guenther@stolaf.edu (Philip A Guenther)
- Subject: Re: How to port this sh script to csh script ?
- In-Reply-To: menjan@cs.umb.edu's message of 11 Jan 93 04:21:59 GMT
- Message-ID: <GUENTHER.93Jan11000533@amcl5.stolaf.edu>
- Lines: 55
- Sender: news@news.stolaf.edu
- Organization: Academic Computing Center, St. Olaf College
- References: <MENJAN.93Jan10232159@ra.cs.umb.edu>
- Distribution: usa
- Date: Mon, 11 Jan 1993 06:05:37 GMT
- Lines: 55
-
- 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
- --
- guenther@stolaf.edu (Philip Guenther) | The ACC might agree with me,
- 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?"
-