Linux Shell Scripting Cheat Sheet/Assign shell variable

Set a shell variable in the current shell.

Section: Variables and Expansion

Assign shell variable

bash
bash
name='alice'
Explanation

Do not put spaces around `=` in shell variable assignments.

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
Capture command output
Assign command output to a variable.
OpenIn sheetbashsame section
Export environment variable
Expose a variable to child processes.
OpenIn sheetbashsame section
Use default value if unset
Expand parameter with a fallback.
OpenIn sheetbashsame section
Require variable to be set
Fail fast if a variable is missing.
OpenIn sheetbashsame section
Quote variable safely
Print variable preserving spaces.
OpenIn sheetbashsame section
Use bash shebang
Start a Bash script with an explicit interpreter.
OpenIn sheetbash2 tag match