问题
I am making this code for a minecraft server plugin updater
I am a new shell scripter so I don't know alot...
when I run this code I get a error:
#!/bin/sh
export PATH=$PATH:.
#Options
PLUGINDOWNLOADLINK=http://api.bukget.org/3/plugins/bukkit/$PLUGINNAME/latest/download
# Plugin folder
if [ -f $PWD\plugins ]; then
PLUG=$PWD\plugins
else
PLUG=$PWD\plug-ins
fi
cd $PLUG
if [ ! -f .\update ]; then
mkdir update
echo Making Directory "update"..
fi
# Plugins Found
for i in $( ls );
do
PLUGINNAME=$i
done
cd .\update
wget $PLUGINDOWNLOADLINK
# No Plugins Found
if [ ! -f $PLUG ]; then
echo
echo
echo No plugin found.
echo
echo
echo
echo Plugins can be downloaded here:
echo http://dev.bukkit.org/bukkit-plugins
fi
# stop
sleep 3s
exit
I get this error:
Syntax error: end of file unexpected (expecting "then")
so I put "then" in the place it wanted me to and ran it again:
it gave me this error now:
Syntax error: end of file unexpected
I wrote it on windows 7 notepad++
how can I fix this?
回答1:
I have met the same problem. And the problem is the format of the file is "dos", but in linux shell requires "unix", so I install the "dos2unix"
$ sudo apt-get install dos2unix
or if you use emacs, you can do this:
C-x RET f unix
Good luck :)
回答2:
- The Unix directory separator is forward slash not backslash.
- Does your editor on windows have an option to save files in "Unix" file format? The shell is seeing the word
then^M
with a carriage return on the end. If you don't have dos2unix then try running this command:sed -i 's/\r$//' filename
回答3:
It's because of file formatting. I faced the same problem. Just create another file with (.sh) extensions using gedit. Then paste the code into the new document. Hope this will resolve the issue.
gedit file-name.sh
来源:https://stackoverflow.com/questions/18155852/syntax-error-end-of-file-unexpected-expecting-then