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