The directory contains report1.log, report9.log, and report10.log.
Match .log files whose character immediately after report is exactly one digit.
Which shell glob is correct?
In a shell glob, [0-9] matches one digit at that position. The number of characters matched differs from * and ?.
Detailed explanation
report*.logIncorrect. * can match zero or more characters, so it also matches report10.log.
Incorrect. * can match zero or more characters, so it also matches report10.log.
report?.logIncorrect. ? matches any one character, not specifically a digit.
Incorrect. ? matches any one character, not specifically a digit.
report[0-9].logCorrect. [0-9] requires exactly one digit before .log.
Correct. [0-9] requires exactly one digit before .log.
report[0-9]*.logIncorrect. The * after [0-9] permits additional characters, including another digit.
Incorrect. The * after [0-9] permits additional characters, including another digit.
Try it yourself
An example you can run in a temporary verification environment.
LAB_DIR=$(mktemp -d)
touch "$LAB_DIR/report1.log" "$LAB_DIR/report9.log" "$LAB_DIR/report10.log"
printf '%s
' "$LAB_DIR"/report[0-9].log | sed 's!.*/!!'
rm -r "$LAB_DIR"Expected result
report1.log
report9.logKey points
- [0-9] matches one digit
- ? matches one character of any kind
- * matches zero or more characters
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.