如何解决"jq: error (at <stdin>:0): Cannot index number with string "说明""
How to solve "jq: error (at <stdin>:0): Cannot index number with string "description""
我使用下面的脚本来获取 GitLab 中一个组的描述。
脚本:
#! /bin/bash
GIT_API="https://git.xxxxxxxxxx.lk/api/v4"
GIT_TOKEN="xxxxxxxxxxxx"
curl -sS --request GET --header "PRIVATE-TOKEN: $GIT_TOKEN" "$GIT_API/groups/1079" | jq -r ".[] .description"
但它输出以下错误:
jq: error (at <stdin>:0): Cannot index number with string "description"
如何解决这个问题。
卷曲输出:
{
"id": 1079,
"web_url": "https://git.xxxxxxxxxx.lk/groups/testdevops",
"name": "testdevops20",
"path": "testdevops",
"description": "Test_1",
"visibility": "private",
"share_with_group_lock": false,
"require_two_factor_authentication": false,
"two_factor_grace_period": 48,
"project_creation_level": "developer",
"auto_devops_enabled": null,
"subgroup_creation_level": "maintainer",
"emails_disabled": null,
"mentions_disabled": null,
"lfs_enabled": true,
"default_branch_protection": 1,
"avatar_url": null,
"request_access_enabled": true,
"full_name": "testdevops20",
"full_path": "testdevops",
"created_at": "2021-05-31T04:56:28.467Z",
"parent_id": null,
"shared_with_groups": [],
"runners_token": "Dw_LPVsbeChD6s6n1wRy",
"projects": []
}
修复脚本如下:
#! /bin/bash
GIT_API="https://git.xxxxxxxxxx.lk/api/v4"
GIT_TOKEN="xxxxxxxxxxxx"
curl -sS --request GET --header "PRIVATE-TOKEN: $GIT_TOKEN" "$GIT_API/groups/1079" | jq -r ".description"
jq
命令在写成 jq -r ".description"
时有效。
我使用下面的脚本来获取 GitLab 中一个组的描述。
脚本:
#! /bin/bash
GIT_API="https://git.xxxxxxxxxx.lk/api/v4"
GIT_TOKEN="xxxxxxxxxxxx"
curl -sS --request GET --header "PRIVATE-TOKEN: $GIT_TOKEN" "$GIT_API/groups/1079" | jq -r ".[] .description"
但它输出以下错误:
jq: error (at <stdin>:0): Cannot index number with string "description"
如何解决这个问题。
卷曲输出:
{
"id": 1079,
"web_url": "https://git.xxxxxxxxxx.lk/groups/testdevops",
"name": "testdevops20",
"path": "testdevops",
"description": "Test_1",
"visibility": "private",
"share_with_group_lock": false,
"require_two_factor_authentication": false,
"two_factor_grace_period": 48,
"project_creation_level": "developer",
"auto_devops_enabled": null,
"subgroup_creation_level": "maintainer",
"emails_disabled": null,
"mentions_disabled": null,
"lfs_enabled": true,
"default_branch_protection": 1,
"avatar_url": null,
"request_access_enabled": true,
"full_name": "testdevops20",
"full_path": "testdevops",
"created_at": "2021-05-31T04:56:28.467Z",
"parent_id": null,
"shared_with_groups": [],
"runners_token": "Dw_LPVsbeChD6s6n1wRy",
"projects": []
}
修复脚本如下:
#! /bin/bash
GIT_API="https://git.xxxxxxxxxx.lk/api/v4"
GIT_TOKEN="xxxxxxxxxxxx"
curl -sS --request GET --header "PRIVATE-TOKEN: $GIT_TOKEN" "$GIT_API/groups/1079" | jq -r ".description"
jq
命令在写成 jq -r ".description"
时有效。