shell 读取配置文件
1.读取文本文件格式一如下:
Setting.ini
1
2> 3 files=profilefile
4
5
6
7 key="com1"
8 file="test1"
9
10
11 key="com2"
12 file="test2"
13
14
15 key="com3"
16 file="test3"
读取方法如下:
[*] function GetKey(){
[*] section=$(echo $1 | cut -d '.' -f 1)
[*] key=$(echo $1 | cut -d '.' -f 2)
[*] sed -n "/\[$section\]/,/\[.*\]/{
[*] /^\[.*\]/d
[*] /^[ \t]*$/d
[*] /^$/d
[*] /^#.*$/d
[*] s/^[ \t]*$key[ \t]*=[ \t]*\(.*\)[ \t]*/\1/p
[*] }" $__CONFIGFILE__
[*] }
[*] __CONFIGFILE__=Setting.ini
[*] #读取实例
[*] pass=$(GetKey "oracle.key")
页:
[1]