See excerpt
on the help let
page,
If the last ARG evaluates to 0, let it return 1; 0 is returned otherwise.
Since the operation is performed after the increment, ((count++))
, the first time 0
saved, so 1
returned
Note that the same does not happen for pre-increment ((++count))
, since the value is set to 1
, at the very first iteration.
$ unset count $ count=0 $ echo $? 0 $ ++count -bash: ++count: command not found $ echo $? 127 $ ((++count)) $ echo $? 0
Inian source share