[comp.unix.questions] Re^2: csh: still trying to read file

maart@cs.vu.nl (Maarten Litmaath) (04/03/89)

jms@hcx.uucp (Michael Stanley) writes:
\...  Keep a variable which
\is the number of the next line you plan to read.  Each time you read
\a line, you can add one to it.  Now, knowing the line number, how do I
\get that line from a file...  Try this:

\	set file_name = "TESTFILE"
\	set line_no = "5"
\	set line_buff = `sed -n "${line_no}p" $file_name`
\	echo $line_buff

So for every line you must skip n - 1 lines first!
Furthermore: how are you going to distinguish eof from empty lines?

\...
\	setenv PATH "/bin:/usr/bin:/usr/local:~yourid/bin"

By this scheme any subcommand that invokes execvp() one way or the other,
will `fail': the environment variable is LITERALLY set to the above, that is,
including the tilde, and the directory "~yourid" isn't the directory you
intended to include (and it probably doesn't exist).
Use `set path=(...)' or `setenv PATH ...$HOME/bin'. RTFM.
Furthermore "~yourid/bin" ("~/bin", for insiders :-) should be the FIRST
directory in your PATH.
-- 
 Modeless editors and strong typing:   |Maarten Litmaath @ VU Amsterdam:
   both for people with weak memories. |maart@cs.vu.nl, mcvax!botter!maart

jms@hcx.uucp (Michael Stanley) (04/04/89)

In article <2239@star.cs.vu.nl>, maart@cs.vu.nl (Maarten Litmaath) writes:
> jms@hcx.uucp (Michael Stanley) writes:
> \...  Keep a variable which
> \is the number of the next line you plan to read.  Each time you read
> \a line, you can add one to it.  Now, knowing the line number, how do I
> \get that line from a file...  Try this:
> 
> \	set file_name = "TESTFILE"
> \	set line_no = "5"
> \	set line_buff = `sed -n "${line_no}p" $file_name`
> \	echo $line_buff
> 
> So for every line you must skip n - 1 lines first!
> Furthermore: how are you going to distinguish eof from empty lines?

Hey, I never SAID it was a GOOD solution.  The n-1 lines isn't pretty,
but I didn't know a better way off the top of my head, and it looked
like no one else was responding.  Someone did post an improvement
which prevented reading the lines FOLLOWING the line to capture.  So
I learned something in the process, and I thought that was great.

Also, I realized when I wrote it that the code couldn't stand alone, or,
in other words, that it would be necessary to determine the number of
lines in the file to prevent the attempt to read past the EOF.  However,
that wasn't the question, so I didn't answer that.  However, if you are
curious, the 'wc' command will supply the number of lines in a file.

> 
> \...
> \	setenv PATH "/bin:/usr/bin:/usr/local:~yourid/bin"
> 
> By this scheme any subcommand that invokes execvp() one way or the other,
> will `fail': the environment variable is LITERALLY set to the above, that is,
> including the tilde, and the directory "~yourid" isn't the directory you
> intended to include (and it probably doesn't exist).
> Use `set path=(...)' or `setenv PATH ...$HOME/bin'. RTFM.
> Furthermore "~yourid/bin" ("~/bin", for insiders :-) should be the FIRST
> directory in your PATH.
> -- 

Actually, you are wrong.  You are right in that, the ~ isn't expanded
when added to the environment, but it still seems to find my bin
directory and execute the commands in it.  If your csh won't do this,
I'm sorry, but every csh I've ever used will.

Finally, if I thought that my every posting would recieve such criticism,
I probably wouldn't post.  Back off a bit, ok?  I just supplied a solution
WHICH WORKS when none others were available.


	Michael Stanley		(...!uunet!harris.cis.ksu.edu!jms@hcx)

jms@hcx.uucp (Michael Stanley) (04/04/89)

I just re-read the note my last note responded to (whew!), and found out
that I completely misread the tone of the former note and flamed back
unnecessarily in response.  Don't worry if you can't figure my last
sentence out, but if you are the person I just flamed at, I'm sorry.

	Michael Stanley

flee@shire.cs.psu.edu (Felix Lee) (04/05/89)

About 'setenv PATH "...:~/bin"', csh does file globbing when it splits
$PATH apart into $path (unless $noglob is set).  But it doesn't export
the globbed names back into $PATH.  Children of your csh probably will
not interpret "~/bin" properly.

The simplest solution is to use "set path = (... ~/bin)" instead.
--
Felix Lee	flee@shire.cs.psu.edu	*!psuvax1!shire!flee