命令行xmllint --schema驗證失敗,但$?返回0linux xmllint架構驗證失敗,但錯誤代碼爲0
myinput.xml:
<myinput><header>mytestvalue</header></myinput>
myschema.xsd
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="myinput" type="xsd:string"/>
</xsd:schema>
命令:
$xmllint --schema myschema.xsd myinput.xml
結果:
命令:
$echo $?
結果:
0
有人能告訴我爲什麼xmllint模式驗證失敗是沒有返回錯誤?或者建議我如何在shell腳本中捕獲這個錯誤? 在我的shell腳本中,當前我在「if」塊中驗證上述xmllint命令,並且它僅失敗了xml格式良好性,但成功進行了模式驗證失敗。
如果上述不返回爲錯誤,我應該在xmllint輸出上執行醜陋的「grep failed」方式來計算模式驗證成功或失敗嗎? 有什麼想法?
有人可以提供一些投入呢? – user1549605
對此有何想法? – user1549605
您是在'xmllint'行還是幾行代碼之後閱讀'$?'? '$?'與_preceding_語句的返回代碼有關,如果你在兩者之間有一個'echo',或者你會讀到'echo'的'$?'。 – vesperto