Linux Shell Scripting Cheat Sheet/Require variable to be set

Fail fast if a variable is missing.

Section: Variables and Expansion

Require variable to be set

bash
bash
echo "${DATABASE_URL:?DATABASE_URL is required}"
Explanation

Great for scripts that should stop immediately when config is missing.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Variables and Expansion
Use default value if unset
Expand parameter with a fallback.
OpenIn sheetbashsame section
Assign shell variable
Set a shell variable in the current shell.
OpenIn sheetbashsame section
Export environment variable
Expose a variable to child processes.
OpenIn sheetbashsame section
Capture command output
Assign command output to a variable.
OpenIn sheetbashsame section
Quote variable safely
Print variable preserving spaces.
OpenIn sheetbashsame section
Check whether file exists
Use a shell test in an if statement.
OpenIn sheetbash1 tag match