在 Bash 中解析配置文件中的变量 [英] Parsing variables from config file in Bash
本文介绍了在 Bash 中解析配置文件中的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在文件中有以下内容:
VARIABLE1="Value1"
VARIABLE2="Value2"
VARIABLE3="Value3"
我需要一个输出以下内容的脚本:
I need a script that outputs the following:
Content of VARIABLE1 is Value1
Content of VARIABLE2 is Value2
Content of VARIABLE3 is Value3
有什么想法吗?
推荐答案
awk -F= '{gsub(/"/,"",$2);print "Content of " $1 " is " $2}' <文件名>
仅供参考,另一种纯 bash 解决方案
Just FYI, another pure bash solution
IFS="="
while read -r name value
do
echo "Content of $name is ${value//"/}"
done < filename
这篇关于在 Bash 中解析配置文件中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文