批处理文件意外退出

时间:2016-03-03 11:51:39

标签: windows batch-file command-line

我正在尝试创建一个bat文件,它将获取git存储库并将其下载到特定目录。

运行此脚本时出现的错误是:

' was unexpected at this time. 

这是我的代码:

@echo off
TITLE Starter Kit
cls

echo "Note: This script will download the 'CodeKit-Starter-Kit' repository from @NicholasAdamou's GitHub."
set /p response="Do you want to continue? <y/n>"

if /i "%response%"=="y" (
    goto :downloadKit

    :downloadKit
    cls
    echo "Downloading the CodeKit-Starter-Kit repository from @NicholasAdamou's GitHub."
    set "filePath=%~dp0"
    cd %filePath%
    cd ../dist
    git clone https://github.com/NicholasAdamou/CodeKit-Starter-Kit.git 'StarterKit (CodeKit)'
)

if /i "%response%"=="n" (
    call exit
)

2 个答案:

答案 0 :(得分:2)

你需要转义git行的括号,如下所示:

git clone https://github.com/NicholasAdamou/CodeKit-Starter-Kit.git 'StarterKit (CodeKit^)'

这是因为批处理视图将括号括起来作为特殊字符

答案 1 :(得分:0)

我不明白     设置“filePath =%~dp0”

尝试用双引号替换git命令中的单引号。

无论如何,我们是在2016年,是时候学习powershell了: - )

$filepath="$home\\dp0"
read-host -prompt "Do you want download it ? " -outvariable response
if ( $response -eq "y"){
     set-location "$filepath\\dist"
     git clone https://github.com/NicholasAdamou/CodeKit-Starter-Kit.git 'StarterKit (CodeKit)'
}