deploy exists in both $HOME/tools/bin and /usr/bin.
Keep the existing PATH but search the trusted home directory first.
Which assignment is appropriate?
PATH is searched from left to right. Prepending a directory gives its same-named command priority over later entries.
Detailed explanation
export PATH="$PATH:$HOME/tools/bin"Incorrect. Appending leaves /usr/bin earlier in the search order.
Incorrect. Appending leaves /usr/bin earlier in the search order.
export PATH="$HOME/tools/bin:$PATH"Correct. $HOME/tools/bin is searched before the existing PATH entries.
Correct. $HOME/tools/bin is searched before the existing PATH entries.
export PATH="$HOME/tools/bin"Incorrect. It removes every existing search directory.
Incorrect. It removes every existing search directory.
export PATH="$PATH"Incorrect. It leaves PATH unchanged and adds nothing.
Incorrect. It leaves PATH unchanged and adds nothing.
Try it yourself
An example you can run in a temporary verification environment.
bash --noprofile --norc -c 'd=$(mktemp -d); printf "#!/bin/sh\n" >"$d/deploy"; chmod +x "$d/deploy"; PATH="$d:/usr/bin:/bin"; command -v deploy; rm -rf "$d"'Expected result
一時ディレクトリ内のdeployパスKey points
- PATH is searched left to right
- Prepending increases priority
- Only trust controlled directories
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.