[英]What is the difference between using “-ne” and “!=” for evaluating the exit code in KornShell (ksh)?
以下兩個KornShell(ksh)代碼段之間的區別是什么,因為到目前為止它們在測試期間的行為都完全相同? 如果重要,則返回代碼(例如,退出代碼,返回狀態,退出狀態,returnCode)來自SQL * Plus命令。
kornShellSnippet1.ksh
returnCode=${?}
if [[ ${returnCode} -ne 0 ]]; then #successful command returns 0#
kornShellSnippet2.ksh
returnCode=${?}
if [[ ${returnCode} != 0 ]]; then #successful command returns 0#
-ne
是數字測試, !=
是字符串測試。 既然您知道$?
是一個數字,使用數字測試很有意義。
據我所知, -ne
是支持向后兼容的傳統語法,而(至少在ksh雙方括號內) !=
等是本機ksh語法。
為了比較數字,您不使用算術語法嗎?
let returnCode=${?}
if (( returnCode != 0 )); then #successful command returns 0#
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.