如何遍历json键,该值是一个数组

时间:2018-01-22 21:57:58

标签: json bash

我对bash有些新意。我的目标是遍历JSON并捕获用户输入并将其导出到环境变量。

这是json的结构。任何帮助将不胜感激!

{
  "items": [{
      "Gitlab": [
        "GITLAB_URL",
        "GITLAB_TOKEN",
        "GITLAB_CHANNEL",
        "GITLAB_SHOW_COMMITS_LIST",
        "GITLAB_SHOW_MERGE_DESCRIPTION",
        "GITLAB_DEBUG",
        "GITLAB_BRANCHES"
      ]
    },
    {
      "PagerDuty": [
        "PAGERV2_API_KEY",
        "PAGERV2_SCHEDULE_ID",
        "PAGERV2_SERVICES",
        "PAGERV2_DEFAULT_RESOLVER",
        "PAGERV2_ENDPOINT",
        "PAGERV2_ANNOUNCE_ROOM",
        "PAGERV2_NEED_GROUP_AUTH",
        "PAGERV2_LOG_PATH"
      ]
    },
    {
      "SLack": [
        "SLACK_TOKEN"
      ]
    }
  ]
}

这是我到目前为止所拥有的

 jq '.items[] | select( .Gitlab| startswith("first-block-"))' < configurations.json

for i in ${items[@]}
do
echo "Enter your " $i
read  input
if [[ ! -z "$input" ]]; then
  export $i=$input
fi
done

0 个答案:

没有答案