4

我在 bash 脚本中使用 xmllint 对某些数据执行 xpath。xpath 并不总是与数据匹配,这没关系。来自 xmllint 文档:

--xpath "XPath_expression"
       Run an XPath expression given as argument and print the result. In case of a nodeset result, each node in the node set is serialized in full in the output. In case of an empty node set the "XPath set is
       empty" result will be shown and an error exit code will be returned.

XPath set is empty当 xmllint 找不到任何匹配项时,是否有禁用/隐藏输出?

4

1 回答 1

7

消息发送到标准错误设备。您可以将其重定向到/dev/null.

例子:

# Shows the message
xmllint --xpath '//a' <(echo "<data/>")

# Redirects the message. Message disappears
xmllint --xpath '//a' <(echo "<data/>") 2>/dev/null
于 2014-05-22T19:32:24.507 回答