Keep the existing standard directories in PATH.
Append $HOME/bin and pass the result to child processes.
Which command is appropriate?
Expand the existing PATH, append a colon and $HOME/bin, and export the result.
Detailed explanation
export PATH="$PATH:$HOME/bin"Correct. It preserves the existing value, appends $HOME/bin, and exports PATH.
Correct. It preserves the existing value, appends $HOME/bin, and exports PATH.
export PATH="$HOME/bin"Incorrect. It discards every existing search directory.
Incorrect. It discards every existing search directory.
export PATH='$PATH:$HOME/bin'Incorrect. Single quotes prevent expansion of $PATH and $HOME.
Incorrect. Single quotes prevent expansion of $PATH and $HOME.
PATH+="$HOME/bin"Incorrect. It omits the colon separator and does not ensure export.
Incorrect. It omits the colon separator and does not ensure export.
Try it yourself
An example you can run in a temporary verification environment.
bash --noprofile --norc -c 'HOME=/tmp/demo-home; PATH=/usr/bin:/bin; export PATH="$PATH:$HOME/bin"; printf "%s\n" "$PATH"'Expected result
/usr/bin:/bin:/tmp/demo-home/binKey points
- Colon separates entries
- Preserve existing PATH
- Export for children
Notes
- Environment: GNU 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.