Question:
Syntax error near unexpected token 'fi' Bash?
Yannick
2012-06-20 07:53:20 UTC
Please help me! i'm creating a bash script but when i execute it says Syntax error near unexpected token 'fi' Bash
Here is the code can you try to find where the error comes from?
The scipt:

#!/bin/bash

#Please don't redistribute this script
#This script need some php scripts for browser based plugin and server settings uploading
#function for plugin config at start :)
function plugin_cfgstart {
if [ $1 = "restore"]
then
restore_backup()
fi
cp -f /minecraftserver /var/www/plugin_edit/minecraftserver
#call plugin manager
plugin_mgr()
}
#function plugin manager :D
function plugin_mgr {
#Copy all plugins to bukkit plugin dir
if [ -f /var/www/plugin_upload/*.jar ]
then
echo 'Handeling plugins...'
cp /var/www/plugin_upload/*.jar /minecraftserver/plugins/
fi
#if there is a file called hello.jar.delete inside '/var/www/plugin_delete', it will cut off the .delete extention and delete /minecraftserver/plugins/hello.jar
if [ -f /var/www/plugin_delete/*.jar.delete ]
then
#it will do it for every file in /var/www/plugin_delete (a do for loop)
for f in /var/www/plugin_delete/*.jar.delete ; do STRDEL="${FILE%.*}"
echo "Deleting plugin $STRDEL..."
rm "/minecraftserver/plugins/$STRDEL"
rm "/var/www/plugin_delete/$STRDEL.delete"
done
fi
#if there is a file called hello.jar.update inside '/var/www/plugin_update', it will cut off the .update extention and replace the /minecraftserver/plugins/hello.jar
if [ -f /var/www/plugin_update/*.jar.update ]
then
#another do for loop
for f in /var/www/plugin_update/*.jar.update ; do STRUPDATE="${FILE%.*}"
echo "Updating plugin $STRUPDATE..."
mv "/var/www/plugin_update/$STRUPDATE" /minecraftserver/plugins/
done
fi
#start function start server
start()
}
#function start server
function start {
#start the craftbukkit.jar
cd minecraftserver
java -Xmx1024M -Xms1024M -jar craftbukkit.jar
echo 'Server stopped!'
quit()
}
#final function: quit?
function quit {
#set a variable choice to 4
choice=4
# Print to console
echo "Do you want to restart?"
echo "1. yes"
echo "2. no"
echo -n "Please choose [1 or 2]? "
# Loop while the variable choice is equal 4
while [ $choice -eq 4 ]; do
# read user input
read choice
#if choice is equal to 1
if [ $choice -eq 1 ] ; then
echo "restarting..."
#load plugin config :D
plugin_cfgend()
plugin_cfgstart()
fi
#if choice is equal to 2 exit script
if [ $choice -eq 2 ] ; then
cp -r /minecraft/plugins /var/www/plugin_edit/
echo "Closing serverscript..."
plugin_cfgend()
exit
fi
}
#restore from backup
function restore_backup {
tar xvfz MCBackup.tar.gz
}
#function plugin config on the end
function plugin_cfgend {
echo 'backing up original...'
echo 'installing new'
mv -f /var/www/plugin_edit/minecraftserver /minecraftserver
}
Three answers:
?
2012-06-20 08:39:14 UTC
You would have given line where you got error

May be give space before ]. Also, the problem is with the function. See the following working code segment follow. Here ss is a function and I am calling it if block.



ss(){

ls

}

if [ "$1" = "restore" ]

then

ss

fi
?
2016-12-17 16:53:59 UTC
Unexpected Token Fi
2016-07-20 07:12:12 UTC
It implies that somewhere on your code you could have something that does not belong, a easy typo in your code. Obviously in case you are programming you understand the debugging system and understand how sneaky syntax bugs can be ;P just re-read over your code and make sure the whole thing matches :) in the event you can not in finding anything email me the code and sick take a appear for ya. Good success :)


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...