2016-03-03 116 views
0

我想制作一个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

你需要躲避的git行的括号,就像这样:

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

这是因为批处理视图关闭括号为特殊字符

+0

感谢您的回答......它更有意义。 –

+1

不是绝对可以肯定的,但据我记忆,'git'也可以接受双引号,所以这也应该可以工作:'git clone https://github.com/NicholasAdamou/CodeKit-Starter-Kit.git“StarterKit CodeKit)“';所以没有必要逃避任何事情...... – aschipfl

0

我不明白 集 “文件路径=%〜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)' 
} 
+0

回应此:我不明白设置“filePath =%〜dp0”我试图让脚本将位置设置为文件的cwd。我尝试过,“尝试用双引号替换git命令中的单引号。”结果没有奏效。所以我会尝试你的片段,看看是否有效。 –

+0

至于''filePath =%〜dp0“',它是批处理代码,意思是设置变量filepath包含当前批处理文件的路径 –

+0

谢谢,我学到了一件新事物。 – dvjz