Yes! But -u
is for undefined variables. It won't stop a defined variable with an empty value. E.g foo=""
.
Also ?
and :?
have the advantage of telling you right then and there where the variable use is that it must be defined or not empty... having to trek back to (likely) the top of the script to check is easily forgotten.
Protects you from accidentally changing the variable within the block too!