我有一个看起来像这样的xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<customer>
<role>probe</role>
<ipconfig>yes</ipconfig>
<hostname>test</hostname>
<ip>192.168.2.123</ip>
<gateway>192.168.2.1</gateway>
<subnet>255.255.254.0</subnet>
</customer>
我在CentOS7下有脚本来使用以下命令获取值:
role="$(xmllint --xpath "string(//role)" "${xml_path}")"
这很好用。
现在我必须在CentOS 6环境下使用相同的功能。没有--xpath支持,我无法安装。
实现同一目标的最简便方法是什么?
答案 0 :(得分:0)
这可能有效:
role=$(echo "cat /customer/role/text()" | xmllint --shell file.xml | grep -v '^/')
输出到变量role
:
probe