A shell script must test whether health.txt contains a line READY.
Do not print the matching text; use only the exit status.
Which option should be added to grep?
grep -q suppresses normal output and returns status 0 for a match and normally 1 for no match, which is suitable for a shell condition.
Detailed explanation
-qCorrect. -q performs the search silently and leaves the match result in the exit status.
Correct. -q performs the search silently and leaves the match result in the exit status.
-sIncorrect. -s suppresses error messages, not normal matching output.
Incorrect. -s suppresses error messages, not normal matching output.
-cIncorrect. -c prints a count rather than suppressing output.
Incorrect. -c prints a count rather than suppressing output.
-lIncorrect. -l prints filenames containing a match.
Incorrect. -l prints filenames containing a match.
Try it yourself
An example you can run in a temporary verification environment.
printf '%s\n' READY > health.txt; grep -q '^READY$' health.txt; printf '%s\n' "$?"Expected result
0Key points
- -q means quiet
- A match returns status 0
- A non-match normally returns status 1
Notes
- Environment: GNU grep 3.x / Bash 5.x
- 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.