繁体   English   中英

在 macOS 上使用 bash 脚本克隆存储库

[英]Cloning a repository with a bash script on macOS

我编写了一个 bash 脚本,该脚本循环遍历包含 SSH URL 的 JSON 数组并将存储库克隆到临时文件夹。

这是 bash 脚本的样子:

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

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

但是当我运行 bash 脚本时,这是生成的 output:

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

编辑:

我之前应该澄清这一点,以确保我们正确的密钥我重新生成了我的密钥。 现在,当我在没有将密钥添加到 SSH 代理的情况下运行克隆命令时,我得到了与预期相同的错误。 使用此命令添加密钥后:

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

我可以很好地下载 repo,但不知何故脚本不能?

您的jq过滤器正在输出 JSON 字符串,例如

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

当您需要适合ssh使用的原始字符串时; 请注意,主机是"git@codebasehq.com ,而不是git@codebasehq.com

对原始 output 使用-r选项。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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