Bash xmllint xpath don';t在空集合上打印错误
我在bash脚本中使用xmllint对一些数据执行xpath。xpath并不总是与数据匹配,这是可以的。从xmllint文档:Bash xmllint xpath don';t在空集合上打印错误,bash,xmllint,Bash,Xmllint,我在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 outp
--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集为空
。您可以将其重定向到/dev/null
例如:
# Shows the message
xmllint --xpath '//a' <(echo "<data/>")
# Redirects the message. Message disappears
xmllint --xpath '//a' <(echo "<data/>") 2>/dev/null
#显示消息
xmllint--xpath'/a'/dev/null
您确认错误消息已写入stderr了吗?您可以使用xmllint放弃所有错误MSG。。。2> /dev/null
或合并输出(失去stdout和stderr之间的区别),如xlmlint。。。2> &1 | egrep-v’XPath集为空|可能是您不关心的其他MSG’
祝您好运。