OA. free
Free
Accenture Core Computer Science Core Computer Science Medium

In UNIX-like OS, when trying to execute a command called foo in the /home/bar directory,...

Accenture technical mcq question, verified with a worked answer. Free to practise - no sign-up.

In UNIX-like OS, when trying to execute a command called foo in the /home/bar directory, the error -bash: foo: command not found was displayed. Which command is used to solve this error?

Choose one option.
Show answer & explanation
Answer: A. export PATH=/home/bar:$PATH

The PATH environment variable determines which directories the shell searches for executable commands. When bash cannot find a command, it means the directory containing that executable is not in PATH. Option A adds /home/bar to the front of PATH, allowing the shell to locate the foo executable. Options B, C, and D modify unrelated variables: PWD tracks the current working directory, MANPATH is for manual pages, and SHLVL tracks shell nesting depth—none solve the command lookup issue.

Step-by-step Derivation:

  1. The error '-bash: foo: command not found' means the shell cannot locate the foo executable in any directory listed in the PATH variable.
  2. The PATH variable is a colon-separated list of directories the shell searches when resolving commands.
  3. To make foo executable from anywhere, we must add /home/bar to PATH.
  4. export PATH=/home/bar:$PATH prepends /home/bar to the existing PATH, preserving existing system directories while adding the new one.
  5. This allows the shell to find and execute foo from /home/bar.