Search messages.txt for the exact text [ready]* including its punctuation.
Do not enumerate escapes for each metacharacter.
Which command is appropriate?
grep -F treats the pattern as a fixed string rather than a regular expression, so metacharacters lose their special meaning.
Detailed explanation
grep '[ready]*' messages.txtIncorrect. The brackets and * are interpreted as regular-expression syntax.
Incorrect. The brackets and * are interpreted as regular-expression syntax.
grep -F '[ready]*' messages.txtCorrect. -F searches for the exact literal sequence [ready]*.
Correct. -F searches for the exact literal sequence [ready]*.
grep -E '[ready]*' messages.txtIncorrect. Extended regular expressions still interpret the metacharacters.
Incorrect. Extended regular expressions still interpret the metacharacters.
grep -w '[ready]*' messages.txtIncorrect. -w changes word-boundary handling but does not disable regex parsing.
Incorrect. -w changes word-boundary handling but does not disable regex parsing.
Try it yourself
An example you can run in a temporary verification environment.
printf 'state=[ready]*\nstate=ready\n' | grep -F '[ready]*'Expected result
state=[ready]*Key points
- -F means fixed string
- Metacharacters are disabled
- fgrep is the historical equivalent
Notes
- Environment: GNU grep 3.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.