“git clone inside bash script: fatal: protocol ‘https’ is not supported”

huangapple go评论77阅读模式
英文:

git clone inside bash script: fatal: protocol '"https' is not supported

问题

我正在编写一个 bash 脚本,该脚本从文件中读取 Github 令牌,然后调用 Github API 获取我的 Github 账户下的存储库,并运行 git clone $url 来克隆响应中的所有网址。脚本如下所示:

#!/usr/bin/env bash

token=$(grep -oP "(?<=\")(.*)(?=\")" config.toml)
curl -H "Accept: application/vnd.github.v3+json" -H "Authorization: token $token" https://api.github.com/user/repos | jq '.[] | .html_url' | while read url; do git clone $url $1; done

然而,我遇到了错误 fatal: protocol 'https' is not supported 在克隆步骤中。然而,当我在 shell 中手动运行 git clone 时,它可以工作。但在运行 bash 脚本本身时却无法正常工作。

可能会发生什么导致 git clone 在 bash 脚本中以这种方式失败,但在 shell 本身中却不会失败呢?我也在 Windows WSL2 下的 Ubuntu 中运行这个。

英文:

I am writing a bash script that reads a Github token from a file, and then calls the Github api to get the repositories under my Github account, and then run git clone $url for all the urls in the response. The script looks like this:

#!/usr/bin/env bash

token=$(grep -oP &quot;(?&lt;=\&quot;)(.*)(?=\&quot;)&quot; config.toml)
curl -H &quot;Accept: application/vnd.github.v3+json&quot; -H &quot;Authorization: token $token&quot; https://api.github.com/user/repos | jq &#39;.[] | .html_url&#39; | while read url; do git clone $url $1; done

However, I am getting the error fatal: protocol &#39;&quot;https&#39; is not supported on the cloning step. When I run git clone manually in the shell however, it works. It only does not work when running the bash script itself.

What could possibly prevent git clone to fail in this manner in a bash script but not inside of the shell itself? I am also running this in Ubuntu under Windows WSL2.

答案1

得分: 1

以下是要翻译的内容:

What could possibly prevent git clone to fail in this manner in a bash script but not inside of the shell itself?

有什么可能会导致在bash脚本中执行git clone失败,但在shell中却不会?

There is no protocol "https, there is https. You have to remove the ".

没有协议"https,应该是https。你需要移除"

Consider researching how to use jq and pass data to bash. Typical solution would be jq -r.

考虑研究如何使用jq并将数据传递给bash。典型的解决方案是jq -r

英文:

> What could possibly prevent git clone to fail in this manner in a bash script but not inside of the shell itself?

There is no protocol &quot;https, there is https. You have to remove the &quot;.

Consider researching how to use jq and pass data to bash. Typical solution would be jq -r

huangapple
  • 本文由 发表于 2023年6月11日 21:04:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76450593.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定