传统source读取方式
#application.properties
db.uat.user=user
db.uat.password=password
db.uat.url=https://www.baidu.com
#!/bin/sh
source "application.properties"
echo $db.uat.user
echo $db.uat.password
curl $db.uat.url
运行start.sh出现command not found.
解决方法:
改成如下方式读取
#!/bin/sh
file="application.properties"
if [ -f "$file" ]
then
echo "$file found."
while IFS='=' read -r key value
do
key=$(echo $key | tr .-/ _ | tr -cd 'A-Za-z0-9_')
if [ "$value"x != x ]; then
eval ${key}=\${value}
fi
done < "$file"
else
echo "$file not found."
fi
echo $db_uat_user
echo $db_uat_password
curl $db_uat_url
效果如下: