#!/bin/sh prop_value="" function getProperty() { file=$1 prop_key=$2 prop_value=`cat $file | grep -w ^${prop_key} | cut -d= -f2` } getProperty $1 $2 echo $prop_value
age=23 sex=男
运行
./GetProperty.sh test.cfg age
输出23
Shell脚本读取属性文件
本文介绍了一个简单的Shell脚本,该脚本用于从配置文件中读取特定的属性值。通过使用`cat`、`grep`和`cut`等命令组合,脚本能够定位并提取指定键对应的值。
#!/bin/sh prop_value="" function getProperty() { file=$1 prop_key=$2 prop_value=`cat $file | grep -w ^${prop_key} | cut -d= -f2` } getProperty $1 $2 echo $prop_value
age=23 sex=男
运行
./GetProperty.sh test.cfg age
输出23
转载于:https://www.cnblogs.com/windyWu/p/5095934.html

被折叠的 条评论
为什么被折叠?