How do I assign a value to a BASH variable iff that variable is null/unassigned/falsey?

Either of these expansions might be what you're looking for, depending on when exactly you want to do the assignment:

Omitting the colon results in a test only for a parameter that is unset. [...]

${parameter:-word}

If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted.

${parameter:=word}

If parameter is unset or null, the expansion of word is assigned to parameter. The value of parameter is then substituted. Positional parameters and special parameters may not be assigned to in this way.

If you just want to set a default on first use, then:

some-command "${FOO:='default value'}"
other-command "$FOO"  # both use 'default value' if FOO was null/unset

If you want to be explicit about it:

FOO=${FOO:-'default value'}
some-command "${FOO}"

Tags:

Bash

Variable