我有一个bash脚本,并且我正在try 基于JSON响应执行命令.
我可以返回3种类型的响应,并存储在content
变量中:
第一种类型(repo不存在):
{
"message": "The repo doesn't exist"
}
第二种类型(回购存在,但没有内容):
[
{
"name": ".dotfile"
},
{
"name": ".anotherdotfile"
},
{
"name": "README.md"
},
]
第三种类型(存在回购且有内容):
[
{
"name": ".dotfile"
},
{
"name": ".anotherdotfile"
},
{
"name": "README.md"
},
{
"name": "myscript.sh"
},
{
"name": "anotherscript.sh"
},
{
"name": "anotherfile.sh"
},
]
在我的脚本中,我有如下循环:
#/bin/bash
for repo_name in "${repos_name[@]}"; do
content=$(curl -s http://example.com/$repo_name)
# Here I would like to check if the response is of the 3rd type.
# So, if it's an array with at least 1 object with value's name
# which not start from "." or equal to "README.md".
# In that case I would perform a command
done
基本上,我想判断是否存在一个repo,它有一些除了点文件和README的内容.
我试着使用jq
工具,但我不知道如何正确过滤内容来执行判断.
我如何才能达到这样的结果呢?