See the excerpt
from the help let
page,
If the last ARG evaluates to 0, let returns 1; 0 is returned
otherwise.
Since the operation is post-increment, ((count++))
, for the very first time 0
is retained, hence returning 1
Notice, the same does not happen for pre-increment ((++count))
, since the value is set to 1
, on the first iteration itself.
$ unset count
$ count=0
$ echo $?
0
$ ++count
-bash: ++count: command not found
$ echo $?
127
$ ((++count))
$ echo $?
0
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…