Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to write a c-shell script that checks for number of arguments and echos a string, but I am getting an unexpected end of file syntax error and I don't understand why.

Here is what I tried:

if ( $#argv == 0 ) then
echo "Enter one or more args"
else
echo "Entry accepted"
endif

Later I tried to output each argument found with this:

if ( $#argv == 0 ) then
echo "Enter one or more args"
else
  foreach arg ( $* )
    echo "Found argument $arg"
  end 
endif

and got a different syntax error "unexpected token `('"

Any help is appreciated

share|improve this question
    
You can get those errors if you ask bash to interpret a csh script. The languages are different iin a number of ways. – Mark Plotnick Dec 13 '15 at 5:51
    
OP mention csh tag. I expect he run csh foo.csh [ blah [ ..]] – Archemar Dec 13 '15 at 8:58

Agreeing with comment by @mark-plotnick, OP has to ensure that the script is run by csh, e.g., by adding the "hash-bang" line:

#!/bin/csh

or running the script using the appropriate program:

csh ./foo

As a general rule, if a script lacks this information it will be run using /bin/sh

Further reading:

share|improve this answer
    
Sorry for the confusion, but I am using the hash-bang line for this. Thank you – Andrew Wong Dec 14 '15 at 1:28
    
Without that line, I and (apparently) Mark get exactly the error messages you reported. With the line, there are none. – Thomas Dickey Dec 14 '15 at 1:31
    
@AndrewWong If you type /bin/csh followed by the file name of the script, do you still get the syntax error messages? It's possible someone has overwritten your csh executable with bash. – Mark Plotnick Dec 14 '15 at 12:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.