Results 1 to 9 of 9
My bash script includes the following:
Code:
# Read config file if it is present.
if [ -r /etc/default/$NAME ]
then
. /etc/default/$NAME
fi
if [ "$STARTUP" = "no" ]; ...
- 04-22-2008 #1Just Joined!
- Join Date
- Feb 2008
- Posts
- 19
Script syntax error but why?
My bash script includes the following:
I get a syntax error when I run itCode:# Read config file if it is present. if [ -r /etc/default/$NAME ] then . /etc/default/$NAME fi if [ "$STARTUP" = "no" ]; then echo "Need to configure config.xml before starting the server" exit 0 fi
/etc/init.d/red5: 32: Syntax error: "fi" unexpected (expecting "then")
where line 32 is the last line with 'fi'Last edited by devils casper; 04-22-2008 at 12:17 PM. Reason: Added [code]...[/code] tag.
- 04-22-2008 #2Just Joined!
- Join Date
- Dec 2006
- Posts
- 52
I think you will find that if you remove "; then" from the second if statement and put "then" on its own line then you will be fine. I can't remember the details as to why that is true but what you have won't work.
- 04-22-2008 #3Linux is not only an operating system, it's a philosophy.
Archost.
- 04-22-2008 #4Just Joined!
- Join Date
- Feb 2008
- Posts
- 19
The original script had the first if fo construct which is fine.
The second one I have introduced to check a variable but it is causing the syntax error. Taking the ; away and putting 'then' on the next line doesn't get rid of the syntax error.
- 04-22-2008 #5
The semicolon syntax is correct if you want to have then on the same line as the if statement. I've seen similar errors when if statements outside/around or above the code had mismatched if:then:fi problems. You might want to look at other tests in your code.
- 04-22-2008 #6Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
- 04-23-2008 #7Just Joined!
- Join Date
- Apr 2008
- Posts
- 35
I cut and pasted your original code and didn't get an error.
It's possible that you have some invisible control characters in your script. Did you ftp it from one place to another (possible ascii/binary problem)? You should be able to see if this is the issue by doing
cat -v yourScript
If it is, the easiest way to fix this is to run dos2unix, or you can edit the file with vi and just replace the control chars with nothing
Hope that helps
, Mike
- 04-23-2008 #8Just Joined!
- Join Date
- Feb 2008
- Posts
- 19
Spot on!
Insidious little error.
- 04-24-2008 #9Just Joined!
- Join Date
- Apr 2008
- Posts
- 35
Good news
Glad I could help you out 
Best wishes,
Mike


Reply With Quote
