-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