简体   繁体   中英

Cloning a repository with a bash script on macOS

I've written a bash script that loops over a JSON array containing the SSH URL's and clones the repository to a temporary folder.

This is what the bash script looks like:

eval "$(ssh-agent -s)"
ssh-add /Users/schotsl/.ssh/id_ed25519

jq -c '.[]' ./../repos.json | while read i; do
    git clone $i
done

But when I run the bash script this is the resulting output:

Cloning into 'krijn-text-4.git"'...
"git@codebasehq.com: Permission denied (publickey).
fatal: Could not read from remote repository.

EDIT:

I should have clarified this before, to make sure the keys we're correct I regenerated my keys. Now when I run the clone command without the keys added to my SSH agent I get the same error as expected. After adding the keys using this command:

ssh-add /Users/schotsl/.ssh/id_ed25519

I can download the repo just fine, but somehow the script can't?

Your jq filter was outputting JSON strings like

"git@codebasehq.com:/path/to/krijn-text-4.git"

when you needed a raw string suitable for use by ssh ; notice that the host was "git@codebasehq.com , not git@codebasehq.com .

Use the -r option for raw output.

jq -cr '.[]' ./../repos.json | while IFS= read -r i; do
  git clone "$i"
done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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