如何让在bash变量配置的价值? [英] how to get value of variable config in bash?
本文介绍了如何让在bash变量配置的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Linux配置文件与这样的格式:
可变= 5753
变量2 =
....
我怎么会得到F.E.使用标准的Linux工具或常规前pressions变量2的值?
(我需要从文件中解析目录路径)。先谢谢了。
解决方案
$>猫./text
变量= 5753
变量2 =
使用 perl的
常规EX pression 的grep
可以用匹配这些值的后向运营商。
$> grep的--only匹配--perl正则表达式(小于?=变量2 \\ =)。*./text
和对变量
:
$> grep的--only匹配--perl正则表达式(小于?=变量\\ = *)。./text
5753
I have a linux config file with with format like this:
VARIABLE=5753
VARIABLE2=""
....
How would I get f.e. value of VARIABLE2 using standard linux tools or regular expressions? (I need to parse directory path from file). Thanks in advance.
解决方案
$> cat ./text
VARIABLE=5753
VARIABLE2=""
With perl
regular expression grep
could match these value using lookbehind operator.
$> grep --only-matching --perl-regex "(?<=VARIABLE2\=).*" ./text
""
And for VARIABLE
:
$> grep --only-matching --perl-regex "(?<=VARIABLE\=).*" ./text
5753
这篇关于如何让在bash变量配置的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文