I found the following statement in the bash manpage (version 4.2) under the Arithmetic Evaluation section.
A shell variable that is null or unset evaluates to 0 when referenced by name without using the parameter expansion syntax.
In the Advanced Bash Scripting Guide, there is a page with the following comment.
# Bash (usually) sets the "integer value" of null to zero #+ when performing an arithmetic operation. # But, don't try this at home, folks! # It's undocumented and probably non-portable behavior.
Here are examples of this behavior:
$ foo= $ let 'foo += 5' $ echo $foo 5 $ unset foo $ let 'foo += 2' $ echo $foo 2
Is it safe to assume that bash will substitute null variables with 0? Could assuming so result in code that is unportable between bash versions?