Results 1 to 2 of 2
hey guys, I'm new to scripting and I have a trouble with if statement syntax.
The code is:
Code:
#there is a diff command here, and it does what i ...
- 12-26-2010 #1Just Joined!
- Join Date
- Dec 2010
- Posts
- 1
Bash Syntax Problem
hey guys, I'm new to scripting and I have a trouble with if statement syntax.
The code is:
so what could be the problem?Code:#there is a diff command here, and it does what i want but #i wanna see 1 if the exit value of diff is 0, and otherwise i wanna see 0. #the problem is here: (syntax error near unexpected token "then") if["$?"==0]; then echo 1 else echo 0 fi
thanks
- 12-26-2010 #2Linux Newbie
- Join Date
- Mar 2010
- Posts
- 121
I think you'll also find you get the following error (assuming you've cut & pasted correctly from your source, and if you don't do that then there's really no way anybody can help you...):
At the very least, you need spaces either side of the `[' and in front of the `]'. Normally, that would be spaced like this for readability:Code:... if[0==0]: command not found
Remember to space things correctly (especially with bash which, as you can see, relies on spaces in some cases to separate tokens) and to always try and fix the first (very very first) error thrown at you. Anything else is a waste of time.Code:if [ "$?" == 0 ];


Reply With Quote
