Introduction
Using set -u helps catch mistakes by stopping the script when you use a variable that has not been set. This prevents unexpected errors later.
When you want to avoid bugs caused by typos in variable names.
When writing scripts that depend on variables being set before use.
When debugging scripts to find missing or unset variables quickly.
When you want your script to fail fast instead of continuing with wrong data.