Schotsl
Schotsl

Reputation: 227

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"'...
"[email protected]: 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?

Upvotes: 0

Views: 610

Answers (1)

chepner
chepner

Reputation: 530950

Your jq filter was outputting JSON strings like

"[email protected]:/path/to/krijn-text-4.git"

when you needed a raw string suitable for use by ssh; notice that the host was "[email protected], not [email protected].

Use the -r option for raw output.

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

Upvotes: 3

Related Questions