簡體   English   中英

使用“ -ne”和“!=”來評估KornShell(ksh)中的退出代碼有什么區別?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM