Тhis is the first script I’ve ever written and I’m looking for some help. I can’t find a script like the one I’m trying to write and its becoming a bother because I wish to create more/expand upon such a bash structure.
If some one has the time could they maybe proof read this for me. Could someone tell me what am I doing wrong and why?
#! /bin/bash
# script to turn the screen blue
echo -e '\033[1;32m'
echo "Minecraft Server LTG Bukkit 1.4.7"
echo "Minecraft Server LTG Bukkit 1.4.7"
echo -e '\033[31m' "[Start ] \033[1;32m LTG MineCraft Server"
echo -e '\033[31m' "[Stop ] \033[1;32m LTG MineCraft Server"
echo -e '\033[31m' "[Restart] \033[1;32m LTG MineCraft Server"
echo -e '\033[0m'
cho -e "Hello, \033[47m \033[30m"$USER" \033[0m Enter Command:"
echo "Command:"
read $COM1 start stop restart
if ["$COM1" = "start"]: then
echo "ran minecraft serv"
if [ "$(pgrep -g java -Xmx256M -Xms256M -jar /minecraft/minecraft_server.jar)" ] ; then
echo MineCraft Server Bukkit 1.4.7 L.T.G : Running
else
echo -e "\033[1;32m MineCraft Server Bukkit 1.4.7 L.T.G : \033[31m FAILED \033[0m"
fi
if ["$COM1" "stop"]: then
echo -e "\033[1;32m MineCraft Server Bukkit 1.4.7 L.T.G : Shutting Down \033[0m"
killall java
if (( "$(pgrep -g java -Xmx256M -Xms256M -jar /minecraft/minecraft_server.jar)" )) ; then
killall java
echo -e "\033[1;32m MineCraft Server Bukkit 1.4.7 L.T.G: is SHUTDOWN \033[0m"
fi
if [ "$COM1" "Restart" ] ; then
echo MineCraft Server Bukkit 1.4.7 L.T.G : Rebooting
exit 1
fi
fi
exit 0
Let’s take two lines…there’s enough there to keep us busy.
The first line reads into a variable whose name is stored in
$COM1(which is uninitialized, so in fact it is empty, so it doesn’t do anything after all), plus the three variablesstart,stop, andrestart. You either need:or you need to initialize
COM1before you use it.The second line manages to run into a surprising number of issues.
testcommand, aka[, is a command name, not a symbol. As such, it needs to be separated from its arguments. Note that there usually is a command/bin/[or/usr/bin/[, though it is also a shell built-in these days.$COM1is unset and empty, it already is separated, but more by accident than design.[command is executed with 3 arguments:=,]:andthen. This is not a valid invocation of[. The last argument should be]on its own.]from thethen.In aggregate, you should have written:
or you can add a semi-colon (which does not have to be separated from the
]by a space) and then thethen:Stylistically, you have the string ‘
Minecraft Server LTG Bukkit 1.4.7‘ repeated all over the place; don’t! Use a variable to hold it.Worry about your embedded cursor control sequences; different terminals have different sequences, so you’re restricted to a single terminal type. Fixing that is harder; investigate the
tputcommand.