An executable named healthcheck is in the current directory.
The current directory is not included in PATH.
Which invocation is correct?
When a command contains a slash, Bash executes the specified path instead of searching PATH. ./ denotes the current directory.
Detailed explanation
healthcheckIncorrect. Without a slash Bash searches PATH and will not find the current directory here.
Incorrect. Without a slash Bash searches PATH and will not find the current directory here.
/healthcheckIncorrect. /healthcheck refers to a file at the filesystem root.
Incorrect. /healthcheck refers to a file at the filesystem root.
~/healthcheckIncorrect. ~/healthcheck refers to a file in the home directory, not the current directory.
Incorrect. ~/healthcheck refers to a file in the home directory, not the current directory.
./healthcheckCorrect. ./healthcheck explicitly names the executable in the current directory.
Correct. ./healthcheck explicitly names the executable in the current directory.
Try it yourself
An example you can run in a temporary verification environment.
LAB_DIR=$(mktemp -d)
( cd "$LAB_DIR"; printf '#!/bin/sh
echo OK
' > healthcheck; chmod +x healthcheck; ./healthcheck )
rm -r "$LAB_DIR"Expected result
OKKey points
- PATH lookup
- The relative path ./
- Execute permission
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.