PATH is /opt/tools/bin:/usr/bin:/bin.
Executable analyze files exist in both /opt/tools/bin and /usr/bin.
Which path is normally selected when analyze is entered?
The shell searches PATH directories from left to right and uses the first executable match it finds.
Detailed explanation
/opt/tools/bin/analyzeCorrect. /opt/tools/bin is the first PATH directory containing an executable named analyze.
/usr/bin/analyzeIncorrect. A standard directory does not outrank an earlier PATH entry.
/bin/analyzeIncorrect. /bin is searched after the two earlier entries and is not stated to contain the file.
Incorrect. Normal command resolution selects one first match rather than running both.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp -d); mkdir -p "$tmp/first" "$tmp/second"; printf '#!/bin/sh\necho first\n' >"$tmp/first/analyze"; printf '#!/bin/sh\necho second\n' >"$tmp/second/analyze"; chmod +x "$tmp/first/analyze" "$tmp/second/analyze"; PATH="$tmp/first:$tmp/second:$PATH" analyze; rm -rf "$tmp"Expected result
firstKey points
- PATH is searched left to right
- The first match is executed
- Order defines priority
Notes
- Environment: Bash 5.x / 一時実行ファイル
- Use disposable shell sessions and harmless commands for experiments.
- Shell behavior can depend on Bash options and distribution defaults.
Foundation review
Place the operation
A standard command lookup does not run all matches; it resolves one candidate according to order and cache state.
Check the side effect
After changing PATH, clear command hashing when needed and inspect the resolved path.