LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-05-2006, 04:09 PM   #1
mattyspatty
LQ Newbie
 
Registered: Jun 2005
Posts: 9

Rep: Reputation: 0
syntax error near unexpected token `


/csgo: line 1: syntax error near unexpected token `in
/csgo: line 1: `case "$1" in

i am making a script so i can easily stop/start/restart my CS server. i found some on the web and mashed em together to create this:
Code:
case "$1" in
	start)
		echo "STARTING SERVER...  use   screen -x CSSERV to view, ctrl-a + D to return"
		screen -A -m -d -S CSSERV ./hlds_run +maxplayers 12 +map de_dust +port 27015 -autoupdate
	;;
	stop)
		echo "STOPPING SERVER...  "
		screen -r CSSERV -X quit
	;;
	restart)
		./csgo stop
		./csgo start
	;;
	*)
		echo "Invalid command!"
	exit 2
esac
exit 0
now i understand this its pretty basic, but i wasnt so sure about the switch/case :S esac? (case backwards?)

anyway, this is a bit of an arse and any help/suggestions would be much appreciated!

Last edited by mattyspatty; 05-05-2006 at 04:30 PM.
 
Old 05-05-2006, 04:22 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
I haven't tried to run your script, but that error looks like your case statement is on line 1 of your script - have you tried it with the script interpreter added? Something like:
Code:
#!/bin/sh
case "$1" in
# The rest of the script goes here
 
Old 05-05-2006, 04:30 PM   #3
mattyspatty
LQ Newbie
 
Registered: Jun 2005
Posts: 9

Original Poster
Rep: Reputation: 0
hmm, that gave me a bad interpreter error, i looked in my bin dir and there is no SH file!
 
Old 05-05-2006, 04:41 PM   #4
zaichik
Member
 
Registered: May 2004
Location: Iowa USA
Distribution: CentOS
Posts: 419

Rep: Reputation: 30
Hmm, works for me. I copied and pasted it as is, and runs as expected. How are you invoking it? Try adding this:

#!/bin/bash

at the beginning, since /bin/sh didn't work.
 
Old 05-05-2006, 04:47 PM   #5
mattyspatty
LQ Newbie
 
Registered: Jun 2005
Posts: 9

Original Poster
Rep: Reputation: 0
still same error.

the script isnt in the root DIR, and i will be executing it from ROOT/home/hlds_1 does this matter while trying to find the file? (as i checked bash DOES exist)

i go to that dir and use ./csgo start to execute, this returns my error.

btw thanks for quick replies
 
Old 05-05-2006, 06:27 PM   #6
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Rep: Reputation: Disabled
If you copied and pasted from a website you might some windows control codes in there so try writing it out from scratch and make sure file format is unix.

You could also try

#! /path/to/bash

make sure you put the leading /
 
Old 05-06-2006, 05:55 AM   #7
pasteNoctem
Member
 
Registered: Apr 2006
Location: Athens Greece
Distribution: Kubuntu
Posts: 35

Rep: Reputation: 15
Quote:
Originally Posted by zaichik
Hmm, works for me. I copied and pasted it as is, and runs as expected. How are you invoking it? Try adding this:

#!/bin/bash

at the beginning, since /bin/sh didn't work.

because it worked for zaichik... I was thinking that your interpreter or compiler is missing something and doesn't recognize the case... while I don't think that's the case... just try re-installing the compiler/interpreter
 
Old 05-06-2006, 06:08 AM   #8
zaichik
Member
 
Registered: May 2004
Location: Iowa USA
Distribution: CentOS
Posts: 419

Rep: Reputation: 30
Quote:
Originally Posted by dive
If you copied and pasted from a website you might some windows control codes in there so try writing it out from scratch and make sure file format is unix.
This is actually a very promising explanation. Even if it wasn't copied from a webpage, if you typed it up on a Windows box and then uploaded it, the problem likely is the file format. Yes, text is text...but there are difference bewteen *nix and Windows, especially in newlines.

Be sure you have opened the script up with a text editor on the server to check for hidden characters. Even if you don't write out the whole thing from scratch, at least rewrite the first line--but do it in-place, on the server, rather than on a Windows box and then uploading.

And just so that there is no confusion, put the sha-bang line as the first line:

#!/bin/bash

No spaces in that. That way, there is no question what the interpreter is (although it looks like bash reporting the errors to me...)

Last edited by zaichik; 05-06-2006 at 06:09 AM.
 
Old 05-07-2006, 05:19 PM   #9
mattyspatty
LQ Newbie
 
Registered: Jun 2005
Posts: 9

Original Poster
Rep: Reputation: 0
yay works. thx alot
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
syntax error near unexpected token `fi' Warmduvet Programming 21 10-08-2013 10:28 AM
error: unexpected token `newline' CarlosV Programming 4 05-17-2011 03:47 AM
/usr/include/stdio.h", line 346: syntax error at token '__s' casady Linux - Software 4 04-28-2006 12:51 AM
Many errors when 'make'ing (example: error: syntax error before `::' token) darkblade Linux - Software 5 03-02-2005 03:00 PM
C++ syntax error before :: token HELP, i cant find the syntax error :( qwijibow Programming 2 12-14-2004 06:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration