Suggested day 1520–30 minutesSafe in practice folder Module milestone

Mission 5 of 5

Environment Variables

Inspect and temporarily change the environment seen by a command.

Understand the configuration values your shell and programs share, including PATH.

Outcome: Variables like HOME and PATH become understandable instead of mysterious.

Mental model

Understand what is happening

Environment variables are KEY=VALUE pairs.

Exported variables are visible to child processes.

PATH tells the shell where to find commands.

Guided lab

Work through the mission

1

Inspect variables

Read-only

Reads common environment variables.

Terminal
printenv | head -20
echo $HOME
echo $USER
echo $SHELL
echo $PATH
2

Export a temporary variable

Safe

Creates and removes a temporary variable.

Terminal
export MY_NAME='Linux Learner'
echo $MY_NAME
bash -c 'echo Child sees: $MY_NAME'
unset MY_NAME
3

Practice PATH safely

Safe

Temporarily adds your practice bin folder to PATH.

Terminal
mkdir -p ~/linux-practice/bin
export PATH="$HOME/linux-practice/bin:$PATH"
which ls
whereis bash
type cd
4

Find the command your shell will run

Read-only

command -v is the portable way to find a command or shell builtin. command -V gives a fuller explanation, while env lists exported variables for the current process.

Terminal
command -v ls
command -v cd
command -V cd
env | sort | head -20

Checkpoint

Verify the mission

A child command sees the exported value and a new shell starts clean.

Try it yourself

One step without a recipe

Locate a practice file, inspect its permissions and owner, start and stop only your own practice process, and capture the relevant environment facts in a report.

Need a hint?

Your PATH is the list of folders your shell searches when you type a command. When "command not found" appears, the command isn't in any of those folders. Check with `echo $PATH`. If you need to add a folder, test it temporarily with `export PATH="/new/folder:$PATH"` before writing it into your shell config file.

Explain it back

Before you move on

  • What does PATH control?
  • What does export do?

Shortcuts:Alt + ← previous lessonAlt + → next lessonAlt + H home? focus search