getValue 方法:
从 config.properties 配置文件中 根据 pname 来获取value :
1 api_1=t_burberry_sales_daily 2 api_2=bz_return_order 3 api_3=bz_return_order_line
1 #!/bin/bash 2 getvalue(){ 3 4 if [ $# -ne 2 ];then 5 echo "you must put one parmes" 6 exit 1 7 fi 8 typeset file=$1 9 typeset key=$2 10 value=`awk -F= -v k=${key} '{ if ( $1 == k ) print $2; }' $file` 11 if [ $? -ne 0 ];then 12 echo " para config.properties file failed" 13 exit 1 14 else 15 if [ "x${value}" = "x" ];then 16 exit 1 17 fi 18 fi 19 20 echo "$value" 21 } 22 getvalue $1 $2
Set 方法:
属性文件 api.properties
- api_1=t_burberry_sales_daily
- api_2=bz_return_order
- api_3=bz_return_order_line
需求:先需要通过shell 脚本将 api_1 的value值替换为 targetValue ;
实现方式:
- sed -i "s#^api_1=.*#api_1=apiName#g" /path