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. – 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:


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 – 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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