Why does it not work (Switch Case)?

Hi there,
I'm trying to run a simple script,but i'm always getting this error

Syntax error: word unexpected (expecting "in")

I have searched many sites,like this,but i dont get it,it looks good so far,but wont work,maybe someone can help me.

Here is the Script

#!/bin/bash
while :
do
clear
echo " [1] - VNC4Server starten "
echo " [2] - VNC4Server stoppen "
echo " [5] - Beenden "
read yourch
case $yourch in
1)killall Xvnc4 ; vnc4server -geometry 1600x900 -depth 24 ; exit ;;
2)killall Xvnc4 ; exit ;;
5)exit 0 ;;
esac
done

Thank you

Try quoting when using your variables (i.e. "$yourch").

Actually, I can't reproduce your error.

Must be a ^M :slight_smile:

$ cat -v script

Added ^M to test and got:

'/t1: line 9: syntax error near unexpected token `in
'/t1: line 9: `case $yourch in
$ cat -v t1
#!/bin/bash
while :
do
clear
echo " [1] - VNC4Server starten "
echo " [2] - VNC4Server stoppen "
echo " [5] - Beenden "
read yourch
case $yourch in^M
1)echo killall 1;;
2)echo killall 2;;
5)exit 0 ;;
esac
sleep 1
done

Suggestion: Remove ^M characters

Got it,when i create/edit the script on WinSCP,it doesnt work,when i create it on Putty it works, is that what you mean with ^M ? I think WinSCP cannot transfer .sh by default, i thin i have too take a look at the settings.

Sorry for creating this useless post,thank you !

Unix uses a single character (^J - linefeed) to represent a new line. Windows uses two characters (^M + ^J - carriage return + linefeed (CRLF)). When transferring a file from Windows to Unix, that was saved in Windows, the ^M (like a snotty hanky) - comes with it. As a rule, Unix admins find this to be mildly irritating.

Thank you for explaining it.I have to take a look at the upload rules of winscp,normally it converts the files while transfering,but since 4-5 months it doesnt,dont know why.

Thank you for helping me ! This problem is really irritating and frustrating :slight_smile:

SCP almost never does this for you. FTP sometimes does, though (which often causes a lot more problems than it solves).

So I'm guessing you had WinSCP to actually use FTP at some point, then switched to SCP.

Really though, you should not be editing script files on windows. UNIX has many perfectly good text editors.