Patrick Brenner Posted March 4, 2013 Posted March 4, 2013 Greetings, everyone! I'm writing a Minecraft startup script for my Ubuntu server box. I mostly do simple Java and C/C++, as I'm only a sophomore in college studying Computer Science: I haven't made it to any other languages yet. Anyways, I'm writing this script in what I believe to be Bash, although the internet sources around this language seem few and far between. Regardless, this is my script: #START SCRIPT# #!/bin/bash ## BEGIN_CONFIG ## MC_PATH=/home/pmbrenner91/Minecraft/TekkitLite BKUP_PATH=/media/external/minecraft/backup SCREEN_NAME="minecraft" ## END_CONFIG ## if [ -e $MC_PATH/server.log.lck ] then ONLINE=1 else ONLINE=0 fi display() { screen -R $SCREEN_NAME } server_launch() { echo "Starting Minecraft server..." cd $MC_PATH screen -m -d -S $SCREEN_NAME java -Xmx${MEMALOC}M -Xms${MEMALOC}M -jar TekkitLite.jar nogui sleep 5 } server_stop() { echo "Stopping Minecraft server..." screen -S $SCREEN_NAME -p 0 -X stuff "`printf "stop.\r"`" sleep 5 } if [$# -gt 0] then case $1 in ## STATUS ## "status") if [$ONLINE -eq 1] then echo "Minecraft server seems ONLINE." else echo "Minecraft server seems OFFLINE." fi;; ## START ## ## ## *) echo "Usage : minecraft < status | start [force] | stop | restart [warn] | logs [clean] | backup [clean] | update >"; esac else if [$ONLINE -eq 1] then display else echo "Minecraft server seems OFFLINE." fi fi exit 0 #STOP SCRIPT# I wrote it using the Notepad++ editor for Windows, and I saved it as a Unix Script File, which enables a file extension of .sh, which I've found to be typical of most programs run using the Linux terminal. So, I try running the file using ./minecraft.sh (the name of the program is minecraft.sh), and I encounter an error saying that I am using a bad interpreter: pmbrenner91@SERVER:~/Minecraft/TekkitLite/Server0.6.0$ ./minecraft.sh -bash: ./minecraft.sh: /bin/bash^M: bad interpreter: No such file or directory So, I run it using <bash minecraft.sh> at which point I receive the following error: pmbrenner91@SERVER:~/Minecraft/TekkitLite/Server0.6.0$ bash minecraft.sh minecraft.sh: line 13: syntax error near unexpected token `$'{\r'' 'inecraft.sh: line 13: `display(){ From my understanding, Windows and Unix/Linux parse new lines differently. Apparently, Windows uses CR and LF, or \r \n to signify new lines in a text file. Unix/Linux uses only LF, or \n. But this leaves me confused, as it waits to line 13 to encounter a parse error. Can anyone help a new programmer? Thanks a million! --PMBrenner91 Quote
Patrick Brenner Posted March 4, 2013 Author Posted March 4, 2013 So, this forum doesn't like my tabs. I posted the script to pastebin.com: http://pastebin.com/DP0kP9eL Quote
holymage! Posted March 4, 2013 Posted March 4, 2013 helpful hint...don't post twice in a row...there is an edit button just letting you know :) Quote
freakachu Posted March 5, 2013 Posted March 5, 2013 probably because the previous parts could be compressed to one line or otherwise handled properly despite incorrect line breaks, but that line can't for whatever reason. if you're writing a bash script, why are you writing it in widows? I assume you have access to a linux machine that you plan to run this on, yes? create the script there. also, you do know your script does basically nothing as it stands, right? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.