Linux module
Lesson 10
Environment variables
PATH, HOME, export, and why secrets do not belong in git or chat.
beginner25 minRun on your machine
What you will be able to do
- Print HOME and PATH and explain what PATH is for
- Set a variable for the current session with export
- Know where API keys should and should not go
Why this matters for DE and AI
Programs look up configuration in the environment: where Python lives, which GPU is visible, what the warehouse password is. Later you will see CUDA_VISIBLE_DEVICES, AWS_PROFILE, and .env files. The rule starts now: secrets are not files you commit, and not text you paste into a website.
Concepts
An environment variable is a named value the shell and child processes can read.
echo $HOME
echo $PATH
$NAME expands the variable. HOME is your home directory. PATH is a list of directories, separated by :, where the shell looks for programs when you type a name.
That is why ./scripts/hello.sh needed ./. The scripts folder is not on PATH.
Set a variable for this terminal only:
export DCUBES_LAB=~/dcubes/linux-lab
echo $DCUBES_LAB
export makes it visible to programs you launch from this shell. Close the window, it is gone — unless you add the line to a startup file (.bashrc or .zshrc). We will not edit startup files in this lesson. One bad line can change every terminal.
.env files (you will meet them in Python) are a convention: a local file of NAME=value lines that tools load. They must stay out of git. Treat them like passwords.
Practice on your machine
echo $HOME
echo $USER
echo $PATH
What you should see: your home path, your username, and a long colon-separated list of directories.
export DCUBES_LAB=~/dcubes/linux-lab
ls $DCUBES_LAB
You should see data, logs, and scripts.
export GREETING=hello
echo $GREETING
bash -c 'echo $GREETING'
Because you exported it, the inner bash should also print hello.
Without export (try in a new thought experiment): GREETING=hi then bash -c 'echo $GREETING' may print nothing. Export is the difference.
Confirm hello.sh is not on PATH:
which hello.sh || echo "not on PATH — use ./scripts/hello.sh"
Common mistakes
- Spaces around
=.export FOO = baris wrong.export FOO=baris right. - Putting secrets in lesson notes or screenshots. Redact.
- Editing
.bashrcby copying a random blog post. Skip that until you can read the file withlessand know how to undo.
Next
What’s running, what’s full — disk, memory, and the two classic DE/AI failures.