Every command inherits an environment: variables like PATH, the current working directory, open file descriptors, and shell options. Understanding the environment prevents “command not found” and permission surprises.
Key environment pieces
PATH— directories searched for executablesHOME— your home directoryPWD— present working directory (maintained by the shell)USER/LOGNAME— account identity
Inspecting the environment
echo "Home: $HOME"
echo "Path: $PATH"
printenv | head
which bash
which gitwhich searches PATH. If Git lessons fail, compare with Git intro install steps in Tools.
Startup files
Login shells read profile files (/etc/profile, ~/.bash_profile). Interactive shells may read ~/.bashrc. Distros differ—when something works in one terminal but not another, compare which file ran.
Important interview questions and answers
- Q: What does PATH control?
A: Which directories are searched, in order, when you type a command name without a full path. - Q: printenv vs env?
A: Both list environment variables;envcan also run a command with a modified environment.
Self-check
- Which variable holds your home directory path?
- What command shows where the bash executable lives?
Tip: If command not found appears, echo $PATH and compare with Tools install docs.
Interview prep
- What is PATH?
Ordered list of directories searched for executable names.
- printenv purpose?
Lists environment variables exported to child processes.