FoundationLinux

Explain PATH, environment variables, and how pipes and redirection work in the shell.

What they are really testing: Core shell literacy, the building blocks of every script and Dockerfile. They want clear mental models, not just examples.

A real interview question

Explain PATH, environment variables, and how pipes and redirection work in the shell.

What most people say

drag me

PATH is where programs are, env vars are settings, and pipes connect commands.

Directionally right but vague: it misses that PATH is an ordered search list, that exported vars are what children inherit, and the stdout/stderr distinction (2>&1) that trips people up constantly.

The follow-ups they ask next

  • You added a binary but the shell still says "command not found". Why?

    It is not on PATH (or PATH was not re-sourced), or the file is not executable (chmod +x), or you are in a new shell that did not load the updated profile. Check with which and echo $PATH.

  • What is the difference between > and 2>&1?

    > redirects stdout only; errors (stderr) still print. 2>&1 redirects stderr to wherever stdout currently goes, so cmd > out.log 2>&1 captures both.

What the interviewer is listening for

  • PATH as an ordered search list
  • Knows exported vars are inherited
  • Distinguishes stdout vs stderr (2>&1)

What sinks the answer

  • Vague "settings/where programs are"
  • Doesn't know 2>&1
  • Can't explain command-not-found

If you genuinely do not know

Say this instead of freezing. Reasoning out loud from what you do know beats silence every single time, and a good interviewer is listening for exactly that.

Env vars are [inherited key-values; export makes children see them]. PATH is [an ordered list of dirs the shell searches for commands]. Pipes [feed stdout into the next stdin]. Redirection: [> overwrite, >> append, < input, 2> stderr, 2>&1 merge errors into stdout].

Keep going with linux

All 336 cloud engineer questions

Knowing the answer is not the same as recalling it under pressure

Sign in to send the questions you fumble to spaced recall, so they come back right before you would forget them, and learn the concepts behind them with hands-on labs.

Start free