简体   繁体   English

语法错误:文件结束意外(期待“然后”)

[英]Syntax error: end of file unexpected (expecting “then”)

I am making this code for a minecraft server plugin updater I am a new shell scripter so I don't know alot... 我正在为Minecraft服务器插件更新程序制作此代码我是一个新的shell脚本编写器所以我不知道很多...
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: 所以我把“then”放在它想要我的地方并再次运行它:
it gave me this error now: 它现在给了我这个错误:

Syntax error: end of file unexpected

I wrote it on windows 7 notepad++ 我是在Windows 7 notepad ++上写的
how can I fix this? 我怎样才能解决这个问题?

  1. The Unix directory separator is forward slash not backslash. Unix目录分隔符是正斜杠而不是反斜杠。
  2. Does your editor on windows have an option to save files in "Unix" file format? 您的Windows编辑器是否可以选择以“Unix”文件格式保存文件? The shell is seeing the word then^M with a carriage return on the end. shell正在看到单词then^M ,末尾有回车符。 If you don't have dos2unix then try running this command: sed -i 's/\\r$//' filename 如果您没有dos2unix,请尝试运行此命令: sed -i 's/\\r$//' filename

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" 问题是文件的格式是“dos”,但在linux shell中需要“unix”,所以我安装了“dos2unix”

$ sudo apt-get install dos2unix

or if you use emacs, you can do this: 或者如果您使用emacs,您可以这样做:

C-x RET f unix

Good luck :) 祝好运 :)

It's because of file formatting. 这是因为文件格式化。 I faced the same problem. 我遇到了同样的问题。 Just create another file with (.sh) extensions using gedit. 只需使用gedit创建另一个带有(.sh)扩展名的文件。 Then paste the code into the new document. 然后将代码粘贴到新文档中。 Hope this will resolve the issue. 希望这能解决问题。

gedit file-name.sh gedit file-name.sh

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM