pklammer@pikes.Colorado.EDU (Peter Klammer) (03/29/89)
Thank you all; yes, I know $< can accept a line from stdin. But what I want is to read a file a line at a time in the midst of a csh script that is in dialogue; that is, redirecting stdin is not acceptable. I have ordered "The UNIX C Shell Field Guide" by Anderson & Anderson, any other recommendations appreciated. Another csh mystery (at least until I get my book, maybe): if I prepare a csh script file (with the mandatory "#" on line 1) and chmod +x it, and then invoke it from a subdirectory, it is run from my HOME directory! I could get around that by alias'ing my command to "source xxx"; is that what one generally does, or is there some way to get my csh script to know what subdirectory is was run from? Thanks.
maart@cs.vu.nl (Maarten Litmaath) (03/29/89)
pklammer@pikes.Colorado.EDU (Peter Klammer) writes:
\... what I want is to read a file a line at a time in the
\midst of a csh script that is in dialogue; that is, redirecting
\stdin is not acceptable.
You don't want csh scripts, if you want to avoid problems. Use sh scripts:
i=0
exec 3< foo
while read bar <&3
do
i=`expr $i + 1`
echo "line $i: $bar"
done
\... Another csh mystery (at least until I get my book, maybe): if I prepare
\a csh script file (with the mandatory "#" on line 1) and chmod +x it,
\and then invoke it from a subdirectory, it is run from my HOME directory! ...
Probably there's a cd command in your .cshrc.
Furthermore, try if your kernel recognizes `#!/bin/csh -f' on line 1.
--
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/01/89)
In article <2130@pikes.Colorado.EDU>, pklammer@pikes.Colorado.EDU (Peter Klammer) writes: > Thank you all; yes, I know $< can accept a line from stdin. > But what I want is to read a file a line at a time in the Well, I'm surprised no one has answered this one by now. My answer may not be the best solution, but it WILL work. 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 As usual, I'm lazy and haven't tested this, but I've done stuff like this before. It isn't pretty but it'll work. > Another csh mystery (at least until I get my book, maybe): if I prepare > a csh script file (with the mandatory "#" on line 1) and chmod +x it, > and then invoke it from a subdirectory, it is run from my HOME directory! If I understand what you are asking, you want to be able to run your new command from any directory as if it were a system command. The best way to do this is to create a directory off YOUR main directory (call it 'bin') and add that directory to your PATH environment variable (which SHOULD be set in your .login file as this is a login parameter which is usually set once and then left alone). An example command to set your PATH from your .login file might be as follows (watch out because every UNIX system seems to have a slightly different set of directories for their system binaries). But over all it should be close to this: setenv PATH "/bin:/usr/bin:/usr/local:~yourid/bin" Notice the important part '~yourid/bin'. This says that after all the system directories are searched to locate a command, YOUR 'bin' directory will be searched. Hope this helps and isn't too vague. Michael Stanley (...!uunet!harris.cis.ksu.edu!jms@hcx)