0

I have been getting this error for about an hour now. It says:

if: Expression Syntax

when I try to run my shell script. I could not find the problem in the code so I shortened everything down to this simple conditional:

if [ $# -eq 0 ]
then
echo "ERROR - no arguments given"
exit 1
fi

I have looked all over the internet and this syntax appears to be flawless.. So why do I still get the if expression syntax error???

1
  • im not sure. i am using a terminal that my school manages. is there a command to find it? Commented Dec 2, 2012 at 21:35

1 Answer 1

2

I think you are using csh/tcsh, so you have to write

if ( $# == 0 ) then
  echo "ERROR - no arguments given"
  exit 1
endif

(With bash your script runs ok here)

Sign up to request clarification or add additional context in comments.

3 Comments

hmmm idk how you knew that but thanks a lot! Actually the first part is right but instead of endif, i still needed fi. No idea why. My professor taught us the wrong syntax to everything
He probably taught you sh and your error is that you use a different shell. They are similar, but still, it's sort of like complaining that the Prolog compiler won't accept C.
@Matt guessed it because it works perfect with bash and the error-msg looks like csh. But that fi your shell wants makes me curious: which system and shell are you using exactly?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.