Git clone from bash script

I am trying to automate my interactions with a Git building 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 

which gives me this error

Access to SSH GitHub is temporarily unavailable (0x09). fatal: the far end unexpectedly hung up

Any light on this would be much appreciated

+7
source share
1 answer

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

Running git clone $repository" "$localFolder is something else entirely:

  • Since none of the variables are in double quotation marks, their contents are separated by lines and extends glob; Thus, if they contained spaces (usually characters inside $IFS ), they could become several arguments, and if they contained globes ( * , [...] etc.), these arguments could be replaced file names (or simply removed from the list of generated arguments if the nullglob shell option is nullglob )
  • Since the space between the two arguments is quoted, they are combined into one argument before passing git .

So, for the values ​​you specified, this script will be executed:

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

... which is very different from

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

... because it passes the path /Users/myname/dev/myfolder as part of the URL.

+13
source

All Articles