I need a little help with my bash script:
#!/bin/bash
zenity --list --title="Select Server" --text="Select the server to start" --radiolist \
--column= --column=Server --column=Port \
FALSE "Creative+Survival" 25565 \
FALSE "Tekkit Cheat Survival" 25566 \
FALSE "Flat Tekkit" 25567 \
FALSE "SunnyDale City" 25568 \
FALSE "Doom Dungeon" 25569 \
FALSE "Survival Tekkit" 25570 \
| cat > ~/temp
server=$(cat ~/temp)
if $server="Creative+Survival" then
gnome-terminal -x sh "/home/kulboy121/Servers/Creative and Survival/launch.sh"
end
else
echo wrong answer...
end
rm ~/temp
This is a script to launch some Minecraft servers I own. I will eventually add if entries for all the other servers as well.
This is the output when I do not select Creative+Survival:
Server Startup - INCOMPLETE.sh: 20: Server Startup - INCOMPLETE.sh: Syntax error: "else" unexpected (expecting "then")
And when I do select Creative+Survival, the same thing happens. Sorry if this is a stupid question, this is one of my first bash scripts.
Thank you!
The bracket
[(test) operator is missing. It should be something like this:NOTE: the spaces around those brackets are important.
The square brackets around the conditional test are actually a synonym for the
testoperator.So the above is equivalent to:
But everyone uses the brackets; I rarely see scripts that use the
testkeyword.Also allowed in the bash shell (although this is not as portable because it is not a POSIX standard) is to use double brackets:
Here’s a link to page that describes the differences between
[,[[, andtest:http://mywiki.wooledge.org/BashFAQ/031
Update
Q: This seems to work, but it spits out an error code if I select anything other then “Creative+Survival”. Is this supposed to happen?
A: It’s not at all clear what error code is being spit out by what component. I expect you want to check for each possible selection. You can do that with an
elif, or with acase.(NOTE: the indentation is to improve readability only; bash cares about the newlines, not the leading spaces.)