Quiz Entry - updated: 2026.06.20
How do you read, use, and delete variables in Bash?
Read a variable by prefixing $` (`$name); use ${name} braces to mark its boundary; remove it entirely with unset name.
Assignment uses the bare name (name=...), but reading always needs the $` to trigger expansion. The braces in `${name} matter when the variable name would otherwise run into following text — bash greedily grabs as many valid name characters as it can, so $namelolo` looks for a variable called `namelolo`. `${name}lolo draws a clear boundary.
name="World"
echo "Hello $name" # Hello World
echo "${name}lolo" # Worldlolo (braces fix the boundary)
echo "$namelolo" # (empty — wrong variable!)
unset name # delete it; $name is now empty
When to use ${var} syntax:
# Problem: variable boundary unclear
echo "$namelolo" # Looks for $namelolo (empty!)
# Solution: curly braces
echo "${name}lolo" # Output: Worldlolo
Deleting variables:
unset name
echo "$name" # Output: (empty)
Check if variable is set:
# Default value if unset
echo "${name:-default}"
# Assign default if unset
name="${name:-default}"
Tip: Always use "$var" (quoted) to prevent word splitting issues.