Scripting
14 min
A shell variable is just a name bound to text: NAME=value sets it (no
spaces around =), and $NAME (or ${NAME}) substitutes its value
anywhere in a later command — including inside another string. export
marks a variable so it's available beyond the current line the same way a
plain assignment is here. Two built-in variables are always available:
$HOME (your home directory) and $PWD (your current directory, updated
automatically by cd). Wrapping a variable in single quotes turns off
expansion — '$NAME' prints the literal four characters $NAME, not its
value; double quotes still expand normally.
NAME=forge
echo hello $NAME
# hello forge
mkdir $NAME
touch $NAME/README.md
export and a plain NAME=value assignment behave the same way in this simulator — there's no subshell boundary here for the distinction to matter. $HOME always resolves to /home/user, the directory every session starts in.
Set a variable `PROJECT` to `forge`, then create a directory named after it and create an empty file `README.md` inside that directory, using the variable both times (not the literal word `forge`).
What's the difference between `echo $NAME` and `echo '$NAME'` (single quotes)?
You can set and use shell variables, and you understand how quoting affects expansion.