简体   繁体   English

从bash脚本克隆Git

[英]Git clone from bash script

I am trying to automate my interactions with Git building a script and I am having the following problem. 我正在尝试自动与构建脚本的Git交互,但遇到以下问题。

This works from the command line: 这可以从命令行使用:

git clone git@github.xxxx.com:blablabla/reponame.git /Users/myname/dev/myfolder

And now I would like to do the same, but from my script. 现在,我想执行同样的操作,但是要从我的脚本开始。 I have the following: 我有以下内容:

#/bin/bash

repository="git@github.xxxx.com:blablabla/reponame.git"

localFolder="/Users/myname/dev/myfolder"

git clone $repository" "$localFolder

that gives me this error 那给我这个错误

GitHub SSH access is temporarily unavailable (0x09). 暂时无法使用GitHub SSH访问(0x09)。 fatal: The remote end hung up unexpectedly 致命:远端意外挂断

Any light on this will be much appreciated 任何光对此将不胜感激

You mean git clone "$repository" "$localFolder" , I'd hope? 您的意思是git clone "$repository" "$localFolder" ,我希望吗?

Running git clone $repository" "$localFolder is something quite different: 运行git clone $repository" "$localFolder完全不同:

  • Because neither variable is within double quotes, their contents are string-split and glob-expanded; 由于这两个变量都不在双引号内,因此它们的内容是字符串分割和glob扩展的; thus, if they contained whitespace (generally, characters within $IFS ), they could become multiple arguments, and if they contained globs ( * , [...] , etc), those arguments could be replaced with filenames (or simply removed from the generated argument list, if the nullglob shell option is enabled) 因此,如果它们包含空格(通常是$IFS内的字符),则它们可能成为多个参数,并且如果它们包含glob( *[...]等),则这些参数可以用文件名替换(或从中删除)生成的参数列表(如果启用了nullglob shell选项)
  • Because the space between the two arguments is quoted, they are combined into a single argument before being passed to git . 因为两个参数之间的空格都用引号引起来,所以在传递给git之前将它们合并为一个参数。

So, for the values you gave, what this script runs would be: 因此,对于您提供的值,此脚本运行的内容是:

git clone "git@github.xxxx.com:blablabla/reponame.git /Users/myname/dev/myfolder"

...which is quite different from ...与

git clone git@github.xxxx.com:blablabla/reponame.git /Users/myname/dev/myfolder

...as it is giving the /Users/myname/dev/myfolder path as part of the URL. ...因为它提供/Users/myname/dev/myfolder路径作为URL的一部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM