标题: 判断语句 [打印本页] 作者: liucody 时间: 2015-09-19 11:27 标题: 判断语句 (( 0 && 1 ))
echo $? # 1 *** 为什么是 1?
# And so ...
let "num = (( 0 && 1 ))"
echo $num # 0 为什么是0
# But ...
let "num = (( 0 && 1 ))"
echo $? # 1 *** 为什么嘛作者: tc1989tc 时间: 2015-09-19 19:01
please man bash. then search \(\( and let:
man bash.
((expression))
The expression is evaluated according to the rules described below under ARITHMETIC EVALUATION. If the
value of the expression is non-zero, the return status is 0; otherwise the return status is 1. This is
exactly equivalent to let "expression".
let arg [arg ...]
Each arg is an arithmetic expression to be evaluated (see ARITHMETIC EVALUATION above). If the last
arg evaluates to 0, let returns 1; 0 is returned otherwise.
? Expands to the exit status of the most recently executed foreground pipeline.