B
B
bormor22018-08-22 08:14:12
bash
bormor2, 2018-08-22 08:14:12

How to do git clone in bash script if repository path contains spaces?

like this - everything works

git clone '/f/Folder name with spaces/' $1 && echo "ok"

like this - it gives an error fatal: Too many arguments.
gitFolder="/f/Folder name with spaces/";
git clone $gitFolder $1 && echo "ok"

What is the reason? How can this be fixed?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Denis, 2018-08-22
@bormor2

Read about quoting and escaping and
correctly add quotes to the gitFolder variable.

C
CityCat4, 2018-08-22
@CityCat4

Wangyu, that's like this:

gitFolder="\"/f/Folder name with spaces/\"";
git clone $gitFolder $1 && echo "ok"

will work

S
Saboteur, 2018-08-27
@saboteur_kiev

gitFolder="/f/Folder name with spaces/";
git clone "$gitFolder" $1 && echo "ok"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question