linux 修改 properties


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
View Code

 

 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
View Code

 

 

 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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM