Git clone from bash script

依然范特西╮ 提交于 2020-04-07 18:50:30

问题


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

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). fatal: The remote end hung up unexpectedly

Any light on this will be much appreciated


回答1:


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

Running git clone $repository" "$localFolder is something quite different:

  • 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"

...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.



来源:https://stackoverflow.com/questions/10857024/git-clone-from-bash-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!