【发布时间】:2022-08-18 01:18:48
【问题描述】:
我有这个使用打印出来的列表gh api命令:
[
{
\"login\": \"anthonyd-cd\",
\"id\": 35614549,
\"node_id\": \"MDQ6VXNlcjM1NjE0NTQ5\",
\"avatar_url\": \"https://avatars.githubusercontent.com/u/35614549?v=4\",
\"gravatar_id\": \"\",
\"url\": \"https://api.github.com/users/anthonyd-cd\",
\"html_url\": \"https://github.com/anthonyd-cd\",
\"followers_url\": \"https://api.github.com/users/anthonyd-cd/followers\",
\"following_url\": \"https://api.github.com/users/anthonyd-cd/following{/other_user}\",
\"gists_url\": \"https://api.github.com/users/anthonyd-cd/gists{/gist_id}\",
\"starred_url\": \"https://api.github.com/users/anthonyd-cd/starred{/owner}{/repo}\",
\"subscriptions_url\": \"https://api.github.com/users/anthonyd-cd/subscriptions\",
\"organizations_url\": \"https://api.github.com/users/anthonyd-cd/orgs\",
\"repos_url\": \"https://api.github.com/users/anthonyd-cd/repos\",
\"events_url\": \"https://api.github.com/users/anthonyd-cd/events{/privacy}\",
\"received_events_url\": \"https://api.github.com/users/anthonyd-cd/received_events\",
\"type\": \"User\",
\"site_admin\": false,
\"contributions\": 5
},
{
\"login\": \"elJoeyJojo\",
\"id\": 17091968,
\"node_id\": \"MDQ6VXNlcjE3MDkxOTY4\",
\"avatar_url\": \"https://avatars.githubusercontent.com/u/17091968?v=4\",
\"gravatar_id\": \"\",
\"url\": \"https://api.github.com/users/elJoeyJojo\",
\"html_url\": \"https://github.com/elJoeyJojo\",
\"followers_url\": \"https://api.github.com/users/elJoeyJojo/followers\",
\"following_url\": \"https://api.github.com/users/elJoeyJojo/following{/other_user}\",
\"gists_url\": \"https://api.github.com/users/elJoeyJojo/gists{/gist_id}\",
\"starred_url\": \"https://api.github.com/users/elJoeyJojo/starred{/owner}{/repo}\",
\"subscriptions_url\": \"https://api.github.com/users/elJoeyJojo/subscriptions\",
\"organizations_url\": \"https://api.github.com/users/elJoeyJojo/orgs\",
\"repos_url\": \"https://api.github.com/users/elJoeyJojo/repos\",
\"events_url\": \"https://api.github.com/users/elJoeyJojo/events{/privacy}\",
\"received_events_url\": \"https://api.github.com/users/elJoeyJojo/received_events\",
\"type\": \"User\",
\"site_admin\": false,
\"contributions\": 2
}
]
我正在尝试使用jq只打印出登录和贡献字段,但像这样进入一行:
gh api repos/eljoeyjojo/diner-app/contributors | jq -r \'.[].login, .[].contributions\'
预期结果
anthony-cd 5
eljoeyjojo 2
实际结果
anthony-cd
eljoeyjojo
5
2
知道如何打印/合并这两个字段吗?在这种情况下我是否必须使用 for 循环?
谢谢