linux shell 读取配置文件的一个例子

Posted SBJBA

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux shell 读取配置文件的一个例子相关的知识,希望对你有一定的参考价值。

配置文件内容如下:

#Created by JInto - www.guh-software.de
#Tue Aug 28 22:20:17 GMT+08:00 2018
aas_amountuser_switch=1
aas_fleet_switch=1
aas_usertokenproct_switch=1
aas_usertokenproct_num=5
aas_devtokenproct_switch=1
......

 

读取脚本如下:

# /bin/bash

configuration_file_path="/opt/some_path/common-conf"

current_value=`grep aas_amountuser_switch ${configuration_file_path}/uiConfig.properties | cut -d = -f2  | sed s/\r//`
echo "$current_value"

if [ "$current_value" = "0" ]; then
  sed -i s/aas_amountuser_switch=0/aas_amountuser_switch=1/ ${configuration_file_path}/uiConfig.properties
  echo "modify uiConfig.properties.aas_amountuser_switch success"
else
  echo "modify uiConfig.properties.aas_amountuser_switch error"
  exit
fi

 

注意:

  linux 中文件的末尾有字符 ‘\r‘,需要注意将换行符去掉

  这种小的点不太容易发现,所以看脚本看不出问题的时候,可以打开 shell 的 debug,很容易定位出来,如下:

    sh -x test.sh

以上是关于linux shell 读取配置文件的一个例子的主要内容,如果未能解决你的问题,请参考以下文章

使用crontab,让linux定时执行shell脚本

Linux shell (ssh批量配置免秘)读取配置文件,进行远程操作

linux shell 如何读取文件特定位置的数据?

linux基础--用户登录时读取配置文件顺序

linux shell脚本读取用户输入的参数

LINUX SHELL读取一个文件,插入到另外一个文件的指定位置