Use test -f app.conf to check whether app.conf exists as a regular file.
Run echo READY only when the check succeeds.
Which command list is correct?
In an AND list, && runs the right-hand command only when the previous command exits with status 0.
Detailed explanation
test -f app.conf && echo READYCorrect. echo runs only when test reports success.
A regular file makes test return zero, allowing the display command to run. An absent path or a directory does not. Comparing both outcomes establishes the required conditional behavior.
test -f app.conf || echo READYIncorrect. || runs its right-hand side when the test fails.
The OR-list operator runs the display when the test is nonzero. It therefore prints READY when the regular-file check fails, reversing the required condition.
test -f app.conf; echo READYIncorrect. ; runs echo regardless of the test result.
The semicolon waits for the test but does not use its status as a condition. READY appears for both successful and unsuccessful checks, which a success-only example would fail to distinguish.
test -f app.conf & echo READYIncorrect. & starts commands asynchronously and does not express a success condition.
The test runs in the background and echo does not wait for its result before executing. Seeing READY does not establish that the background check succeeded; its result would need separate collection with wait.
Try it yourself
An example you can run in a temporary verification environment.
LAB_DIR=$(mktemp -d) || exit 1
(
cd "$LAB_DIR" || exit 1
: > app.conf
mkdir dir.conf || exit 1
test -f app.conf && printf 'present: READY\n'
test -f missing.conf && printf 'missing: READY\n'
printf 'missing status=%s\n' "$?"
test -f dir.conf && printf 'directory: READY\n'
printf 'directory status=%s\n' "$?"
rm -- app.conf
rmdir -- dir.conf
)
rmdir -- "$LAB_DIR"Official references
- Official documentation 1
- Official documentation 2
- Official documentation 3
- Official documentation 4
- Official documentation 5
Expected result
present: READY
missing status=1
directory status=1Key points
- Short-circuit evaluation with &&
- Exit status 0
- Conditional execution
Notes
- Environment: Bash 5.2 / GNU coreutils in a fresh process with errexit off. Compare a regular file, an absent path, and a directory inside a newly created temporary directory.
- Use a fresh Bash process and names inside the newly created temporary directory. Cleanup names only the created file and empty directories; it does not use recursive removal.
- Read $? immediately after the relevant AND list. An intervening command replaces the status being observed.
Foundation review
Observe both branches
With a regular file, &&, a semicolon, and a background operator can all produce READY. Use absent-path and directory cases to check when the display is skipped.
Status is different from output
test normally reports its decision through a numeric exit status rather than printing a value. The condition for && is zero, not text written to standard output.
Check the file type
The -f condition means a regular file. An existing directory is not sufficient for that condition.