由于(Bourne)Shell变量不能包含点,因此可以用下划线替换它们。阅读每一行,翻译。在_和评估的关键。
#/bin/shfile="./app.properties"if [ -f "$file" ]then echo "$file found." while IFS='=' read -r key value do key=$(echo $key | tr '.' '_') eval ${key}=${value} done < "$file" echo "User Id = " ${db_uat_user} echo "user password = " ${db_uat_passwd}else echo "$file not found."fi请注意,以上仅翻译。到_,如果您使用更复杂的格式,则可能需要使用其他翻译。最近,我不得不解析一个包含许多讨厌字符的完整Ant属性文件,在那我必须使用:
key=$(echo $key | tr .-/ _ | tr -cd 'A-Za-z0-9_')



