来自bash脚本的Git克隆 [英] Git clone from bash script

查看:401
本文介绍了来自bash脚本的Git克隆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试自动与构建脚本的Git交互,并且遇到以下问题.

I am trying to automate my interactions with Git building a script and I am having the following problem.

这可从命令行使用:

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

这给我这个错误

GitHub SSH访问暂时不可用(0x09).致命:远端意外挂起

GitHub SSH access is temporarily unavailable (0x09). fatal: The remote end hung up unexpectedly

对此表示感谢

推荐答案

您的意思是git clone "$repository" "$localFolder",我希望吗?

You mean git clone "$repository" "$localFolder", I'd hope?

运行git clone $repository" "$localFolder完全不同:

  • 由于两个变量都不在双引号内,因此它们的内容是字符串拆分和glob扩展的;因此,如果它们包含空格(通常是$IFS中的字符),则它们可以成为多个参数,如果它们包含glob(*[...]等),则可以将这些参数替换为文件名(或将其删除)从生成的参数列表中,如果启用了nullglob shell选项)
  • 因为两个引号之间的空格都被引号引起来,所以在传递给git之前将它们合并为单个引数.
  • Because neither variable is within double quotes, their contents are string-split and glob-expanded; 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)
  • Because the space between the two arguments is quoted, they are combined into a single argument before being passed to 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"

...与

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

...因为它在URL中提供了/Users/myname/dev/myfolder路径.

...as it is giving the /Users/myname/dev/myfolder path as part of the URL.

这篇关于来自bash脚本的Git克隆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆