我有一个看起来像这样的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 支持,我无法安装它。
实现相同目标的最简单方法是什么?
这可能有效:
role=$(echo "cat /customer/role/text()" | xmllint --shell file.xml | grep -v '^/')
输出到可变role
:
探针