在EOF错误之后,bash脚本没有正确退出(期待);

时间:2012-01-03 12:29:58

标签: bash eof

我的以下脚本产生错误(它抱怨在文件退出之前需要'then'关键字。我找不到错误。如果你有时间,请帮忙。

谢谢你, 丝兰

#!/bin/sh
#Makes the /usr/lib/jvm in case...
sudo mkdir -p /usr/lib/jvm;
sudo mkdir /org-thejarbar-work-dir;
cd /org-thejarbar-work-dir;

#Update this line to reflect newer versions of JDK...
wget http://download.oracle.com/otn-pub/java/jdk/7u1-b08/jdk-7u1-linux-i586.tar.gz;

#Extract the download
tar -xvf ./*gz;

#Move it to where it can be found...
sudo mv ./* /usr/lib/jvm/;
sudo ln -s /usr/lib/jvm/jdk1*/bin/java /usr/bin/;
sudo rm -rf /org-thejarbar-work-dir;

#Makes the /usr/lib/maven in case...
sudo mkdir -p /usr/lib/maven;
sudo mkdir /org-thejarbar-work-dir;
cd /org-thejarbar-work-dir;

#Update this line to reflect newer versions of maven
wget http://mirrors.powertech.no/www.apache.org/dist//maven/binaries/apache-maven-3.0.3-bin.tar.gz;
tar -xvf ./*gz;

#Move it to a more logical location
sudo mv ./* /usr/lib/maven/;

#If you have Maven on Windows and use VirtualBox, you can set up the maven to be a virtualbox shared folder.
#The name must match the name used below (ignore if irrelevant to you).
sudo mount -t vboxsf maven /usr/lib/maven;

#Link the new Maven to the bin...
sudo ln -s /usr/lib/maven/apache-maven-*/bin/mvn /usr/bin/;
sudo rm -rf /org-thejarbar-work-dir;
sudo mkdir /org-thejarbar-work-dir;
cd /org-thejarbar-work-dir;

#Update this line to reflect newer versions of Netbeans or replace 'javase' with 'javaee' or add Java EE manually via
#Netbeans 'plugins as needed.
wget http://download.netbeans.org/netbeans/7.0.1/final/bundles/netbeans-7.0.1-ml-javase-linux.sh;
sh //*sh;
sudo mv ./* /usr/lib/ide/;

#Add Netbeans launcher to your PATH. Doing so allows you to run 'netbeans' command from the terminal
sudo ln -s /usr/lib/ide/netbeans-7*/bin/netbeans /usr/bin/;

#If you use VirtualBox , you can share your projects between Host and guest. Name of shared
#folder must match 'NetBeansProjects' Remove this if you don't need...
if [ ! -d "~/NetBeansProjects" ]; then
    sudo mkdir ~/NetBeansProjects;
fi

sudo mount -t vboxsf NetBeansProjects ~/NetBeansProjects;
sudo rm -rf /org-thejarbar-work-dir;
sudo mkdir /org-thejarbar-work-dir;
cd /org-thejarbar-work-dir;

#Update this line to reflect newer versions of Netbeans or replace 'javase' with 'javaee' or add Java EE manually via
#Netbeans 'plugins as needed.
wget http://download.netbeans.org/netbeans/7.0.1/final/bundles/netbeans-7.0.1-ml-javase-linux.sh;
sh //*sh;
sudo mv ./* /usr/lib/ide/;

#Add Netbeans launcher to your PATH. Doing so allows you to run 'netbeans' command from the terminal
sudo ln -s /usr/lib/ide/netbeans-7*/bin/netbeans /usr/bin/;

#If you use VirtualBox , you can share your projects between Host and guest. Name of shared
#folder must match 'NetBeansProjects' Remove this if you don't need...
if [ ! -d "~/NetBeansProjects" ]; then
    sudo mkdir ~/NetBeansProjects;
fi

sudo mount -t vboxsf NetBeansProjects ~/NetBeansProjects;
sudo rm -rf /org-thejarbar-work-dir;
sudo mkdir /org-thejarbar-work-dir;
cd /org-thejarbar-work-dir;
sudo wget http://download-ln.jetbrains.com/idea/ideaIC-11.tar.gz
sudo tar -zxvf ./*.gz;

#Move it to a better location...
sudo rm -rf /usr/lib/ide/idea-IC*;
sudo mv ./* /usr/lib/ide/;

#Add IDEA launcher to your PATH. Doing so allows you to run 'idea.sh' command from the terminal
rm /usr/bin/idea.sh;
sudo ln -s /usr/lib/ide/idea-IC*/bin/idea.sh /usr/bin/;

#If you use VirtualBox , you can share your projects between Host and guest. Name of shared
#folder must match 'IdeaProjects' Remove this if you don't need...
if [ ! -d "~/IdeaProjects" ]; then
    sudo mkdir ~/IdeaProjects;
fi

sudo rm -rf /org-thejarbar-work-dir;

exit 0;

请注意,该脚本可以正常工作(执行所需的操作),但由于我正在努力将此脚本共享给其他人,因此该错误很麻烦。我试图避免错误。

2 个答案:

答案 0 :(得分:3)

首先,这不是现在的bash脚本 - 它是一个bourne shell脚本。如果你想使用bash改变第一行(“shebang”)来使用/bin/bash。您在评论中显示系统中/bin/sh实际上是dash。 dash是bourne shell的最小实现。

您可以通过使用-x运行bash脚本来调试bash脚本,如:/bin/bash -x script.sh;或者将shebang改为#!/bin/bash -x(暂时)。

顺便说一句,您正在测试目录并在它们不存在时创建它们。如果您要在if子句中执行所有操作,则可以使用普通mkdir -p,因此如果路径已存在则不会引发错误。请注意,它可能并非在所有* nix系统中都可用,但它位于GNU / Linux中。

答案 1 :(得分:1)

查看sh //*sh;,看看有什么匹配的脚本? 此行基本匹配并运行以/路径下的sh结尾的任何脚本。