新增bash工具函数
This commit is contained in:
parent
08bd9c8402
commit
1fcad6d680
17
bin/utils/jq_util.sh
Normal file
17
bin/utils/jq_util.sh
Normal file
@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 修改json文件的属性值
|
||||
# 调用方式:modify_json_file "/foo/bar.json" "person.name" "张三"
|
||||
function modify_json_file() {
|
||||
local json_file=$1 # json文件路径
|
||||
local key=$2 # 要修改的key
|
||||
local value=$3 # 要修改的value
|
||||
|
||||
#如果key的值是.开头, 则去掉.号
|
||||
if [[ ${key} == "."* ]]; then
|
||||
key=${key:1}
|
||||
fi
|
||||
|
||||
jq ".${key} = \"${value}\"" ${json_file} > ${json_file}.tmp
|
||||
mv ${json_file}.tmp ${json_file}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user