当前位置: 技术问答>linux和unix
怎样用shell读取properties里面某个键对应的值,再赋值给shell中的变量
来源: 互联网 发布时间:2017-01-03
本文导语: 如:CONFIG.properties文件内容 SQL_PATH="/temp/aaa/bbb" DB_SID=server1 DB_USER=user1 DB_PASS=pass1 想在shell中把CONFIG.properties文件的值分赋值给变量 SQL_PATH DB_SID DB_USER DB_PASS 本人新手求高人帮忙 | #!/bin/sh while read linemsg do ...
如:CONFIG.properties文件内容
SQL_PATH="/temp/aaa/bbb"
DB_SID=server1
DB_USER=user1
DB_PASS=pass1
想在shell中把CONFIG.properties文件的值分赋值给变量
SQL_PATH
DB_SID
DB_USER
DB_PASS
本人新手求高人帮忙
SQL_PATH="/temp/aaa/bbb"
DB_SID=server1
DB_USER=user1
DB_PASS=pass1
想在shell中把CONFIG.properties文件的值分赋值给变量
SQL_PATH
DB_SID
DB_USER
DB_PASS
本人新手求高人帮忙
|
#!/bin/sh
while read linemsg
do
key=$(echo $linemsg | cut -d = -f 1)
value=$(echo $linemsg | cut -d = -f 2)
if [ "$key" = "SQL_PATH" ];then
SQL_PATH=$value
elif [ "$key" = "DB_SID" ];then
DB_SID=$value
elif [ "$key" = "DB_USER" ];then
DB_USER=$value
elif [ "$key" = "DB_PASS" ];then
DB_PASS=$value
fi
done
while read linemsg
do
key=$(echo $linemsg | cut -d = -f 1)
value=$(echo $linemsg | cut -d = -f 2)
if [ "$key" = "SQL_PATH" ];then
SQL_PATH=$value
elif [ "$key" = "DB_SID" ];then
DB_SID=$value
elif [ "$key" = "DB_USER" ];then
DB_USER=$value
elif [ "$key" = "DB_PASS" ];then
DB_PASS=$value
fi
done