010-150 · Question #83
Which command shows if /usr/bin is in the current shell search path?
The correct answer is B. echo $PATH. In POSIX shells, environment variables are referenced with a $ prefix, so echo $PATH prints the value of the PATH variable which contains the shell's search directories.
Question
Which command shows if /usr/bin is in the current shell search path?
Options
- Acat PATH
- Becho $PATH
- Cecho %PATH
- Dcat $PATH
- Eecho %PATH%
How the community answered
(30 responses)- A3% (1)
- B70% (21)
- C3% (1)
- D17% (5)
- E7% (2)
Why each option
In POSIX shells, environment variables are referenced with a $ prefix, so echo $PATH prints the value of the PATH variable which contains the shell's search directories.
cat PATH treats 'PATH' as a filename and attempts to read a file named PATH in the current directory, not the environment variable.
The PATH environment variable stores a colon-separated list of directories the shell searches for executables. Using echo $PATH causes the shell to expand $PATH to its value and print it, allowing you to see whether /usr/bin is included in the search path.
The %PATH syntax is the Windows Command Prompt convention for environment variables and is not valid in POSIX/bash shells.
cat $PATH attempts to use the value of PATH as a filename to read, which would fail since PATH contains directory paths separated by colons, not a single file.
The %PATH% syntax is the Windows Command Prompt convention and is not valid in POSIX/bash shells.
Concept tested: Displaying shell environment variable PATH value
Source: https://www.gnu.org/software/bash/manual/bash.html#index-PATH
Topics
Community Discussion
7B is the correct answer. In a Unix shell, PATH is an environment variable, and you read environment variables with a leading dollar sign. echo $PATH tells the shell to expand that variable and print its value, so you see a colon-separated list of directories like /usr/local/bin:/usr/bin:/bin, and you just scan it to confirm /usr/bin is there. The other options fail for obvious reasons: cat reads files, not variables, so cat PATH tries to open a file literally named PATH and cat $PATH tries to open a file whose name matches the value of PATH, neither of which makes sense here. The percent-sign syntax is Windows CMD, not Unix, so C and E are wrong the moment you remember what OS the 010-150 exam is about.
Got this one on my actual exam last month and almost second-guessed myself because I kept mixing up the Windows percent signs from my old desktop support days. My senior had drilled it into me the week before, he literally walked me to a terminal and said "echo dollar sign PATH, that is it, commit that to muscle memory," and it saved me right there in the testing center.
Muscle memory is fine but the real win is knowing why it works, because the moment the exam throws env or printenv at you for the same job, you won't freeze up wondering if you memorized the wrong thing.
I actually glanced at A first because "cat PATH" feels plausible if you half-remember that PATH is a file somewhere, but PATH is a shell variable, not a file, so cat on a bare word like that just throws an error. C and E are Windows cmd and batch syntax respectively, which rules them out on any Linux exam item. D is interesting because $PATH does expand the variable, but cat expects a file argument and $PATH expands to something like /usr/local/bin:/usr/bin:/bin, which is not a path to any file, so that fails too. echo $PATH is the right call because echo just prints its arguments to stdout, the shell expands $PATH before echo even sees it, and you get the colon-separated list right there to scan for /usr/bin.
One thing I would add is that printenv PATH also works and my senior actually prefers it over echo $PATH because it skips the shell expansion step entirely, so you are reading the variable directly from the environment rather than relying on the shell to expand it first.
echo $PATH prints the shell's PATH variable, showing every directory searched.
That is accurate, though the more important card to make is the one that captures when PATH lookup does NOT happen, meaning commands with a slash in them bypass PATH entirely and the shell invokes the file directly.