运行简单脚本时只需为用户创建一个repo就会出现这两个错误。
这是一个bash脚本
ERROR:
./ createMyRepo.sh:第48行:在寻找匹配的“”
时出现意外的EOF./ createMyRepo.sh:line 52:语法错误:意外的文件结尾
#!/bin/bash
# This script is used to automate the repo
if [ -z `$1` ]
then
echo "No user was input, please input a user and try again"
exit
else
cd /home/$1
if [ $? -eq 0 ]
then
echo "Successfully changed directory to user's home"
else
echo "Failed to cd directory, trying to create directory now."
mkdir /home/$1
if [ $? -eq 0 ]
then
echo "Successfully created the directory location
else
echo "Failed to create directory, exiting."
exit
fi
fi
mkdir project.git
if [ $? -eq 0 ]
then
echo "Succesfully created project.git directory"
else
echo "Failed to create project.git directory attempting to see if the directory already exists"
cd project.git
if [ $? -eq 0 ]
then
echo "Successfully changed to this directory"
else
echo "This directory cannot be created and does not exist. exiting..."
exit
fi
fi
cd project.git
echo "creating git repo"
git --bare init
if [ $? -eq 0 ]
then
echo "DONE Created repo"
else
echo "FAIL repo did not create"
fi
fi
答案 0 :(得分:0)
行echo "Successfully created the directory location
最后缺少"
,因此Bash完全混淆了字符串的位置和不存在。
(Hat-tip to Stack Exchange的语法突出显示,这使问题显而易见!)
另外,我建议你采用更好的缩进方案;您当前的方案使得跟踪嵌套if
等非常困难。
答案 1 :(得分:0)
oops ...看起来像拼写错误
echo "Successfully created the directory location
应采用以下形式:
echo "Successfully created the directory location"