I just did a system update and got configuration diffs like:


- i=$(($i + 1))
+ : $(( i += 1 ))

If you don’t know : builtin yet, from bash(1):

: [arguments]
No effect; the command does nothing beyond expanding arguments and performing any specified redirections. A zero exit code is returned.

I have been using it quite often with infinite while loop, e.g.


while :; do
do_something
done

I never thought of putting something behind it, and that diff is quite genius in my opinion. However I will just write


(( i++ ))

I don’t see there is a reason for using Arithmetic Expansion, Evaluation is enough and clear. Expansion will returns the expanded string, which cause command execution if you don’t prefix with :, and you will get a “command not found” error.

There is a good use of :, putting it after last command of a function or last command of a script, if they have chances to return non-zero and you do not care if that command runs into problem. This way it will clear out the returned value.

Another use is to Assign Default Values if environment variable is not assigned by user, for example:


: ${VAR:=foobar}