shell脚本读取配置文件

来源:互联网 发布:简单的数据库设计 编辑:程序博客网 时间:2024/05/16 00:54

我现在有个配置文件config,里面内容为
ID=123
IP=192.168.3.154
Name=test
想写个shell脚本,把这几个变量的值给读出来
高手指点下

 

Answer:

[root@RHEL6A shcode]# more config
ID=123
IP=192.168.3.154
Name=test

[root@RHEL6A shcode]# echo $ID
0
[root@RHEL6A shcode]# more sh13.sh
#!/bin/bash
source config
echo $ID
echo $IP
echo $Name
[root@RHEL6A shcode]# ./sh13.sh
123
192.168.3.154
Name

 

提供3种方法
while read -r line
do
  eval "$line" 
done < configfile
echo $ID

#id=`sed '/^ID=/!d;s/.*=//' configfile`
#echo $id

source configfile
echo $ID