1.使用 jq
brew install jq
2.json文件如下
{
"plist_url": "xxx",
"apk_url": "xxx",
"title": "xxx"
}
3.遍历脚本
title=app下载
project_pub_path=app/main_71
plist_url=https://xxx.com/files/$project_pub_path/app.plist
apk_url=https://xxx.com/files/$project_pub_path/bhfae.apk
cat h5_path/config.json |
jq 'to_entries |
map(if .key == "plist_url"
then . + {"value":"'${plist_url}'"}
elif .key == "apk_url"
then . + {"value":"'${apk_url}'"}
elif .key == "title"
then . + {"value":"'${title}'"}
else .
end
) |
from_entries' >tmp.json
mv tmp.json h5_path/config.json
输出
{
"plist_url": "https://xxx.com/files/app/main_71/app.plist",
"apk_url": "https://xxx.com/files/app/main_71/bhfae.apk",
"title": "app下载"
}
用到了 jq 的 if elif
jq 'if . == 0 then "zero" elif . == 1 then "one" else "many" end'
Input 2
Output "many"
引用 jq手册
网友评论