1. 配置文件
[server]
ip=127.0.0.1
passwd=pass
2. shell脚本
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__
}
#读取实例
pass=$(GetKey "server.passwd")
__CONFIGFILE__是配置文件路径
转自 http://shenling258-hotmail-com.iteye.com/blog/1454087