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 foo: command not found was displayed. Which command is used to solve this error?
Show answer & explanation
The foo: command not found error occurs because the shell cannot locate the executable in any directory listed in the PATH environment variable. Option A adds /home/bar to the front of PATH, allowing the shell to search that directory for executables. PWD tracks the current directory, MANPATH locates manual pages, and SHLVL tracks shell nesting depth—none of these solve command resolution.
Step-by-step Derivation:
When a command is executed, the shell searches directories in the PATH variable from left to right. If foo is located in /home/bar but that directory is not in PATH, the shell cannot find it. export PATH=/home/bar:$PATH prepends /home/bar to the existing PATH, ensuring the shell checks that directory first. This is the standard solution for resolving 'command not found' errors when the executable exists but is in a non-standard location.