010-160 · Question #37
Which of the following commands adds the directory /new/dir/ to the PATH environment variable?
The correct answer is E. export PATH=/new/dir: $PATH. To prepend a directory to the PATH variable in bash, use the export command with correct variable assignment syntax and a colon separator between the new path and the existing PATH expansion.
Question
Options
- A$PATH=/new/dir: $PATH
- BPATH=/new/dir: PATH
- Cexport PATH=/new/dir: $PATH
- Dexport $PATH=/new/dir: $PATH
- Eexport PATH=/new/dir: $PATH
How the community answered
(58 responses)- A2% (1)
- B10% (6)
- C2% (1)
- D5% (3)
- E81% (47)
Why each option
To prepend a directory to the PATH variable in bash, use the export command with correct variable assignment syntax and a colon separator between the new path and the existing PATH expansion.
$PATH= attempts to assign to the shell's expanded value of PATH rather than the variable name itself, which is invalid bash syntax.
Missing the export keyword means the updated PATH exists only in the current shell and is not inherited by child processes.
A space between the colon and $PATH breaks the PATH string into two words during assignment, preventing correct path concatenation.
Using $PATH on the left side of the assignment (export $PATH=) attempts to assign to the expanded string rather than the variable name, which is invalid syntax.
The export keyword makes the variable available to child processes. The assignment PATH=/new/dir:$PATH uses the bare variable name on the left side, places the new directory first, separates it from the current value with a colon, and expands the existing PATH using $PATH on the right - all required elements for correct PATH manipulation.
Concept tested: Modifying PATH environment variable in bash
Source: https://www.gnu.org/software/bash/manual/bash.html#index-export
Topics
Community Discussion
No community discussion yet for this question.