Surfalytics
CLI course overview

Just Enough CLI · Step 6 Free

Variables, PATH, and special characters

Every broken tool installation ends with someone saying “check your PATH”. This topic makes that sentence make sense.

Shell variables

The shell stores temporary text values in shell variables. Assign with = (no spaces!) and read with $:

HOST=127.0.0.1
echo $HOST

Environment variables

An environment variable is like a shell variable, with one key difference: the operating system passes environment variables to every program the shell runs. Shell variables stay inside the shell.

Promote a shell variable with export:

STUFF=blah
export STUFF

This matters daily in data work: AWS_PROFILE, DBT_PROFILES_DIR, DATABASE_URL — tools read their settings from environment variables. Putting export lines into ~/.zshrc makes them permanent.

PATH — how the shell finds commands

PATH is a special environment variable holding a list of directories the shell searches when you type a command:

echo $PATH
/usr/local/bin:/usr/bin:/bin

When you type python, the shell walks these directories in order and runs the first python it finds. “Command not found” means the program’s directory is not in PATH. Two commands you will use when debugging installs:

which python     # which file actually runs
echo $PATH       # what the shell searches

Special characters

Learn to read these fluently — they appear in every script and Stack Overflow answer:

SymbolNameMeaning
*starwildcard / regex repeat
.dotcurrent directory; one char in regex
!bangnegation, command history
|pipeconnect commands
/slashdirectory separator
\backslashescape the next character
$dollarread a variable
'single quoteliteral string (nothing expands)
"double quotestring where $vars still expand
^caretstart of line (regex)
~tildehome directory
#hashcomment
[ ]bracketscharacter ranges
{ }bracesblocks, ranges
_underscorespace substitute in names

The quoting difference is worth remembering: echo '$HOST' prints $HOST literally; echo "$HOST" prints the value.

Practice in your terminal:

  1. Create a variable: NAME=yourname, then echo $NAME.
  2. Run echo $PATH and count the directories (they are separated by :).
  3. Run which git and which python — see where they live.
  4. Compare echo '$NAME' and echo "$NAME".