英文:
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 "(?<=\")(.*)(?=\")" 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
However, I am getting the error fatal: protocol '"https' 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 "https
, there is https
. You have to remove the "
.
Consider researching how to use jq
and pass data to bash. Typical solution would be jq -r
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论