我在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.
当xmllint没有找到任何匹配项时,是否仍然禁用/隐藏输出XPath set is empty
?
答案 0 :(得分:5)
消息转到标准错误设备。您可以将其重定向到/dev/null
。
示例:
# Shows the message
xmllint --xpath '//a' <(echo "<data/>")
# Redirects the message. Message disappears
xmllint --xpath '//a' <(echo "<data/>") 2>/dev/null