The current PATH contains the standard search directories.
Add $HOME/bin at the front while preserving the existing directories.
Which assignment is correct?
PATH entries are colon-separated and searched from left to right. Expanding the old value after the new directory preserves existing commands.
Detailed explanation
PATH="$HOME/bin:$PATH"Correct. $HOME/bin is searched first and the old PATH remains after it.
Correct. $HOME/bin is searched first and the old PATH remains after it.
PATH="$PATH"Incorrect. It leaves PATH unchanged.
Incorrect. It leaves PATH unchanged.
PATH="$HOME/bin"Incorrect. It discards all existing search directories.
Incorrect. It discards all existing search directories.
PATH="$PATH;$HOME/bin"Incorrect. Semicolons are not PATH separators on Unix systems.
Incorrect. Semicolons are not PATH separators on Unix systems.
Try it yourself
An example you can run in a temporary verification environment.
( PATH="$HOME/bin:$PATH"; printf '%s
' "$PATH" )Expected result
先頭がホームディレクトリ/binで、後ろに元のPATHが続くKey points
- Colon-separated PATH entries
- Search order
- Preserving the old value
Notes
- Environment: Bash 5.2
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.