如何在Shell脚本中读取一个配置文件并使用其中的值?
#!/bin/bash
# 读取配置文件
config_file="config.conf"
# 检查配置文件是否存在
if [ ! -f "$config_file" ]; then
echo "$config_file 不存在"
exit 1
fi
# 读取配置值
config_value=$(grep "^key=" "$config_file" | cut -d'=' -f2)
# 使用配置值
echo "配置文件中的值为: $config_value"