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

In a UNIX-like OS, executing command foo from /home/bar displays bash: foo: command not found.

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

In a UNIX-like OS, executing command foo from /home/bar displays bash: foo: command not found. Which command resolves this by adding the directory to the execution path?

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 foo in any directory listed in the PATH environment variable. Option A correctly exports an updated PATH that includes /home/bar at the beginning, allowing the shell to find and execute foo. Options B, C, and D are incorrect: B modifies PWD (working directory), not the search path; C removes all permissions making the file unexecutable; D changes ownership, which doesn't resolve the path issue.

Step-by-step Derivation:
Step 1: Understand the problem. The shell searches for executables only in directories listed in the PATH variable. Step 2: Analyze each option:

  • A: export PATH=/home/bar:$PATH prepends /home/bar to the existing PATH, making the shell search there for foo.
  • B: export PWD=/home/bar only changes the printed working directory variable; it doesn't affect command search.
  • C: chmod 000 foo removes all permissions (read, write, execute); this makes the file unexecutable, worsening the problem.
  • D: chown root foo changes file ownership; this doesn't affect whether the directory is in PATH. Step 3: Option A is the correct solution because it modifies the PATH variable to include the directory where foo resides.