[comp.unix.ultrix] reading stdin for tcsh script

farmer@media-lab.MEDIA.MIT.EDU (Bill Farmer) (01/17/91)

I am working on an ultrix platform, with tcsh.  I want
to input from stdin into shell scripts.  In bourne
this function is 'read'.  In c shell, and therefore
presumably tc shell, this is effected with the symbol
$<, e.g. set superstar = $<.  This set command will 
work fine from the shell itself, so that subsequently when
i enter echo $superstar, the string I typed and entered immediatley
after the set command is correctly echoed.  However when i 
include this command in a script, errors occur.  A simplified 
example of my desired use is as follows:

	echo Enter NAME :
	set title = $<
	echo  Name : $title

if this is run like this, as a 3 line script i get the error 
message 'line 3 newline not expected'.  if i variously apply
quotes and double quotes in line 2, the program will execute 
but will not pause to read in the data from stdin, but will 
assign title the null string.
	anyone got a handle on what's happening here?  if 
a newline is not expected, what is expected? not ; and not \,
attempts using these result in messages saying that they're
not expected, either. 

				bill farmer
				farmer@media-lab.media.mit.edu

jik@athena.mit.edu (Jonathan I. Kamens) (01/17/91)

  Your shell script is not working because it is being evaluated by the bourne
shell, not by the C shell.  If you want your shell script to be evaluated by
the C shell, then put "#!/bin/csh -f" as the first line of the script (and
hope that either your kernel or your shells understand the "#!" notation; I
believe ultrix does).

Here's the script without a shell specification at the top:

    % cat test
    echo Enter NAME :
    set title = $<
    echo  Name : $title

Here's what happens when you run it:

    % ./test
    Enter NAME :
    ./test: syntax error at line 3: `newline' unexpected

Now we put a shell specification at the top:

    % ed test
    53
    1i
    #!/bin/csh -f
    .
    w
    67
    q

And run it again:

    % ./test
    Enter NAME :
    John Doe
    Name : John Doe
    %

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710

tchrist@convex.COM (Tom Christiansen) (01/18/91)

Anyone who uses the csh or its derivatives for writing
scripts is simply asking to be abused.

--tom
--
"Hey, did you hear Stallman has replaced /vmunix with /vmunix.el?  Now
 he can finally have the whole O/S built-in to his editor like he
 always wanted!" --me (Tom Christiansen <tchrist@convex.com>)