-1
这是我的第一个脚本,所以请温和。我知道文件语法错误的意外结束通常是一个如果没有一个fi,因为没有完成或缺失的引号等我找不到以上任何。我有一种感觉,它可能是我试图用echo写入文件httpd.conf的代码的一部分,但我不确定。任何人都可以发现最新的错误,提示,建议吗?谢谢。Bash脚本行106:语法错误:意外的文件结尾
enter code here#!/bin/bash
INSTALL_DIRECTORY=/home/jared
export INSTALL_DIRECTORY
cd ; pwd
#If statement to create directories if they are not made
if test -d apache2 && if test -d www2
then
echo "Directories already exist"
else
mkdir apache2 www2
fi
cd apache2
#If statement to create files if they are not made
if test -d bin
then
echo "Directory already exists"
else
mkdir bin
fi
if test -d conf
then
echo "Directory already exists"
else
mkdir conf
fi
if test -d lib
then
echo "Directory already exists"
else
mkdir lib
fi
cd /home/jared/www2
if test -d html
then
echo "Directory already exists"
else
mkdir html
fi
if test -d cgi-bin
then
echo "Directory already exists"
else
mkdir cgi-bin
fi
if test -d ftp
then
echo "Directory already exists"
else
mkdir ftp
fi
#Changing the permissions
chmod -R 755 apache2 ; chmod -R 750 www2
cd www2 ; chmod 722 ftp ; cd ../apache2/bin
#Creating the files
touch httpd ; chmod 755 httpd ; cd /home/jared/www2/html
touch index.html ; chmod 644 index.html ; cd ../cgi-bin
touch process.pl ; chmod 711 process.pl
cd ; cd /home/jared/apache2/conf
#Creating the httpd.conf file if it does not already exist
#and adding details
if test -s httpd.conf
then
echo "File already exists"
else
echo '#
#This is the main Apache HTTP server configuration file.It contains
#configuration directives that give the server its instructions.
#Do not add a slash at the end of the directory path.
#
ServerRoot "/home/jared/apache1"
#
#DocumentRoot: The directory out of which you will server your documents.
#
DocumentRoot "/home/jared/www1"' > /home/jared/apache2/conf/httpd.conf
fi
chmod 644 /home/jared/apache2/conf/httpd.conf
echo $INSTALL_DIRECTORY
请看看:http://www.shellcheck.net/ – Cyrus
BTW:伯恩壳牌(SH)不的Bourne Again Shell的(庆典)。 – Cyrus
我如上所述去了shellcheck,我不知道什么是错的 – Apache