LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   syntax error near unexpected token ` (https://www.linuxquestions.org/questions/programming-9/syntax-error-near-unexpected-token-%60-441992/)

mattyspatty 05-05-2006 04:09 PM

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!

gilead 05-05-2006 04:22 PM

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


mattyspatty 05-05-2006 04:30 PM

hmm, that gave me a bad interpreter error, i looked in my bin dir and there is no SH file!

zaichik 05-05-2006 04:41 PM

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.

mattyspatty 05-05-2006 04:47 PM

:( 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 :D

dive 05-05-2006 06:27 PM

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 /

pasteNoctem 05-06-2006 05:55 AM

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

zaichik 05-06-2006 06:08 AM

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...)

mattyspatty 05-07-2006 05:19 PM

yay :D works. thx alot :D


All times are GMT -5. The time now is 08:48 AM.