dp-agent.properties
token=11111
读取文件
get_property() {
key=$1
# 读取properties文件
value=$(grep "^$key=" ./config/dp-agent.properties | sed 's/^[^=]*=//')
echo $value
}
用法
token=$(get_property "token")
写入文件
update_property() {
key=$1
value=$2
# 读取properties文件
property=$(grep "$key" ./config/dp-agent.properties)
# 写入properties文件
if [[ -z $property ]]; then
echo "$key=$value" >> ./config/dp-agent.properties
else
sed -i "s|$key=.*|$key=$value|" ./config/dp-agent.properties
fi
}
用法
update_property "token" "$token"