我一直收到语法错误(意外的文件结束)。语法看起来不错,但这里显然有些错误。我希望外面的人能够从洞察力中提供。
read -p "Create default hosts file?: " yn
case $yn in
[Yy] ) echo "Creating default hosts file"
sleep 1
cat <<-EOF1 > /etc/hosts
Do not remove the following line, or various programs that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
192.168.1.1 test01
192.168.1.2 test02
192.168.1.3 test03
EOF1
if [ "$(wc -m /etc/hosts)" == "215 /etc/hosts" ] ; then
echo -e "Default Hosts file\e[1;32m COMPLETE \e[0m"
else
echo -e "Default hosts file\e[1;31m FAILED \e[0m"
sleep 1
echo "Please correct before continuing"
echo "EXITING..."
sleep 1
exit
fi;;
[Nn] ) echo 'Searching "/etc/hosts" for test03 entry'
sleep 1
grep "test03" /etc/hosts >/dev/null
if [ "$?" -eq 0 ] ; then
echo "Entry found!"
echo "Setup Continuing..."
else
echo '"test03" entry not found'
sleep 1
echo "Please correct before continuing"
sleep 1
echo "EXITING..."
sleep 1
exit
fi;;
* ) echo "Please answer [Yy] or [Nn].";;
esac
答案 0 :(得分:3)
此处文档结束标记应该是除了制表符之外的第一行:
cat <<-EOF1 > /etc/hosts
Do not remove the following line, or various programs that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
192.168.1.1 test01
192.168.1.2 test02
192.168.1.3 test03
EOF1