010-100 · Question #65
Which command shows all of the directories that the shell searches for programs?
The correct answer is B. echo $PATH. The $PATH environment variable holds a colon-separated list of directories the shell searches for executables; echo prints its current value to stdout.
Question
Which command shows all of the directories that the shell searches for programs?
Options
- Aless $PWD
- Becho $PATH
- Cmore $ALL_PATH
- Dget $PATH
- Ecat $PATH
How the community answered
(30 responses)- A17% (5)
- B70% (21)
- C3% (1)
- D7% (2)
- E3% (1)
Why each option
The $PATH environment variable holds a colon-separated list of directories the shell searches for executables; echo prints its current value to stdout.
$PWD holds the current working directory, not the executable search path, so less $PWD would attempt to page through a directory listing, not show search paths.
echo $PATH expands the PATH environment variable and prints its value, which is the ordered list of directories the shell searches when resolving command names. This is the standard, built-in mechanism for inspecting the executable search path on any POSIX-compatible shell.
$ALL_PATH is not a standard shell environment variable and does not exist by default on any POSIX system.
get is not a standard shell built-in or common utility; no such command exists for printing environment variables.
cat reads file contents by path; $PATH expands to a string of directory names, so cat $PATH would attempt to open a file whose name is that string, not print the variable's value.
Concept tested: Inspecting the shell executable search path variable
Source: https://www.gnu.org/software/bash/manual/html_node/Bourne-Shell-Variables.html
Topics
Community Discussion
No community discussion yet for this question.