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

Q3 (1/20) In UNIX-like OS, when trying to execute a command called foo in the /home/bar...

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

(1/20)

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 command not found error occurs because the shell cannot locate the executable in its search path. The PATH environment variable defines which directories the shell searches for executables. Adding /home/bar to PATH (option A) makes the shell search that directory. Option B modifies PWD (current working directory), option C is for manual page paths, and option D sets shell nesting level—none solve the executable lookup problem.

Step-by-step Derivation:
When you type a command like foo, bash searches for it in directories listed in the PATH variable (left-to-right). If foo is in /home/bar but that directory isn't in PATH, bash returns 'command not found'. The fix is to add /home/bar to PATH: export PATH=/home/bar:$PATH prepends /home/bar to the existing PATH, so bash will search there first. The $PATH preserves existing paths, preventing loss of system commands.