I have a script which contains the
true $(( var-- ))
$(( var-- ))
To complement λuser's helpful answer:
true $(( var-- )) is a way to perform a variable assignment without causing (additional) side effects:
$(( ... ))- expands to (is replaced with) the result of the calculation/assignment.
true, its result is effectively ignored, because
trueignores any arguments you pass to it.
++aren't POSIX-compliant, as λuser points out.
:is the null utility, whose express purpose is to expand, but otherwise ignore its arguments, while always setting the exit code to
Thus, to remain POSIX-compliant (when used in a script targeting
/bin/sh), you should use:
: $(( var-=1 ))
However, if you can assume
zsh, you can use
--, and also simply omit the
$ to get an arithmetic evaluation that does not expand to anything:
(( var-- ))
Or, to ensure exit code
0 (the exit code usually doesn't matter in the body of a loop):
: (( var-- ))
(( ... )) sets its exit code to
1 if the calculation results in
0, and to
0 for any nonzero result, which allows direct use in conditionals (
if (( ... )); then ...), as an arithmetic/Boolean alternative to
[ ... ] /
[[ ... ]] conditionals.
 Note that POSIX does allow for
-- and even
(( ... )), but only as optional extensions, so you cannot assume their presence on all platforms.