200-901 · Question #446
Within a Bash shell, which command adds the current directory to the PATH without overwriting the current PATH for this shell and any subshells that are spawned from the current shell?
The correct answer is C. export PATH=$PATH:$(pwc1). The correct command is export PATH=$PATH:$(pwd). Breaking it down: export makes the variable available to the current shell AND any subshells spawned from it. $PATH references the existing PATH value so it is preserved (not overwritten). $(pwd) uses command substitution to…
Question
Within a Bash shell, which command adds the current directory to the PATH without overwriting the current PATH for this shell and any subshells that are spawned from the current shell?
Options
- Aexport $PATH=PATH:$(pwd)
- Bset PATH=$PATH:${pwd}
- Cexport PATH=$PATH:$(pwc1)
- Dset PATH=PATH+$(pwd)
How the community answered
(59 responses)- A7% (4)
- B2% (1)
- C90% (53)
- D2% (1)
Explanation
The correct command is export PATH=$PATH:$(pwd). Breaking it down: export makes the variable available to the current shell AND any subshells spawned from it. $PATH references the existing PATH value so it is preserved (not overwritten). $(pwd) uses command substitution to execute the pwd command and insert the current directory path. Note: the option as printed shows $(pwc1), which appears to be a typo for $(pwd). Option A is wrong because $PATH=PATH:$(pwd) places the dollar sign incorrectly-the variable being assigned should not have $ on the left side of =. Option B uses set, which is a shell built-in for positional parameters and does not export variables to subshells. Option D also uses set with incorrect syntax and does not use $PATH to preserve existing entries.
Topics
Community Discussion
No community discussion yet for this question.