Variables in Bash
From the Bash Scripting cheat sheet · Variables & Quoting · verified Jul 2026
Variables
Assignment, usage, and scope.
bash
# Quick Reference
name="Sam" # NO spaces around =
echo "$name" # use with $
echo "${name}" # braces for clarity/adjacency💡 No spaces around = in assignments: name="Sam" (name = "Sam" runs a command).
⚡ Use ${var} braces when the name touches other text: ${name}_backup.
📌 Declare function variables with local so they do not leak into the global scope.
🟢 export makes a variable visible to child processes; plain assignment stays in the shell.
variablesscope