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"
echo "Entry accepted"

Later I tried to output each argument found with this:

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

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

Any help is appreciated

  • You can get those errors if you ask bash to interpret a csh script. The languages are different iin a number of ways. Dec 13, 2015 at 5:51
  • OP mention csh tag. I expect he run csh foo.csh [ blah [ ..]]
    – Archemar
    Dec 13, 2015 at 8:58

1 Answer 1


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:


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:

  • Sorry for the confusion, but I am using the hash-bang line for this. Thank you Dec 14, 2015 at 1:28
  • Without that line, I and (apparently) Mark get exactly the error messages you reported. With the line, there are none. Dec 14, 2015 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. Dec 14, 2015 at 12:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .