0

在运行一个简单的脚本来为用户创建一个 repo 时出现这两个错误。

这是一个 bash 脚本

错误:

./createMyRepo.sh:第 48 行:寻找匹配的“”时出现意外 EOF

./createMyRepo.sh:第 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
4

2 回答 2

0

该行最后echo "Successfully created the directory location缺少 a ",因此 Bash 完全混淆了您的字符串在哪里和不在哪里。

(对 Stack Exchange 的语法高亮的提示,这使得问题显而易见!)

另外,我建议您采用更好的缩进方案;您当前的方案使得跟踪嵌套if的 s 等变得非常困难。

于 2013-10-05T21:04:22.623 回答
0

哎呀......看起来像一个错字错误

echo "Successfully created the directory location

应该是这种形式:

echo "Successfully created the directory location"
于 2013-10-05T21:04:46.087 回答