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 form a character class and the star repeats it.
grep -F '[ready]*' messages.txtCorrect. -F searches for the exact literal sequence [ready]*.
Correct. -F preserves every punctuation mark as literal text.
grep -E '[ready]*' messages.txtIncorrect. Extended regular expressions still interpret the metacharacters.
Incorrect. Extended mode still treats brackets and the star as syntax.
grep -w '[ready]*' messages.txtIncorrect. -w changes word-boundary handling but does not disable regex parsing.
Incorrect. -w changes word boundaries but does not disable regular-expression 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
- Use temporary files and harmless commands for pattern experiments.
- Regular-expression details should be checked against the target GNU implementation.
Foundation review
Place the condition
Fixed-string mode is simpler and safer when the target text contains brackets or repetition symbols.
Check the result
Compare a literal [ready]* line with a line containing only ready.