我不知道为什么下面指示的行返回1而((count))的后续执行返回0.
[me@server ~]$count=0 [me@server ~]$echo $? 0 [me@server ~]$count++ -bash: count++: command not found [me@server ~]$(count++) -bash: count++: command not found [me@server ~]$((count++)) [me@server ~]$echo $? 1 <------THIS WHY IS IT 1 AND NOT 0?? [me@server ~]$((count++)) [me@server ~]$echo $? 0 [me@server ~]$((count++)) [me@server ~]$echo $? 0 [me@server ~]$echo $count 3
请参阅帮助允许页面中的摘录,
If the last ARG evaluates to 0,let returns 1; 0 is returned
otherwise.
由于操作是后递增的,((计数)),第一次保留0,因此返回1
注意,对于预增量((count))也不会发生同样的情况,因为在第一次迭代时,该值设置为1.
$unset count $count=0 $echo $? 0 $++count -bash: ++count: command not found $echo $? 127 $((++count)) $echo $? 0