所以我很清楚退出代码0被认为是程序运行成功。然后我们在 bash 脚本中使用它逻辑AND并OR根据第一个程序的退出状态运行下一个程序。一个很好的例子可以在这里找到:https : //unix.stackexchange.com/a/187148/454362
这是否意味着0被解释为真而任何其他数字但零被解释为假?这与我所知道的所有编程语言都相反。那么我可以假设 bash 内部使用逻辑NOT将退出代码反转为正确的 false / true 值吗?
所以,这些是一些例子:
#should result in false, and bash shows 0 as false
echo $(( 1 && 0 ))
# should result in true, and bash shows 1 as true
echo $(( 1 || 0 ))
# does not show 'hi'; even though if false is zero per first example, then
# this should be considered success exit code …Run Code Online (Sandbox Code Playgroud)