The directory contains report1.csv, report7.csv, reportA.csv, and report10.csv.
Select names with exactly one digit after report.
Which pattern is appropriate?
The bracket expression [0-9] matches one character in the digit range, selecting exactly one numeric character.
Detailed explanation
report?.csvIncorrect. ? matches any character, so reportA.csv would also match.
Incorrect. ? matches any character, so reportA.csv would also match.
report[0-9].csvCorrect. report[0-9].csv matches one numeric character only.
Correct. report[0-9].csv matches one numeric character only.
report[!0-9].csvIncorrect. [!0-9] selects a non-digit, the opposite condition.
Incorrect. [!0-9] selects a non-digit, the opposite condition.
report*.csvIncorrect. * allows zero or more characters and would also match report10.csv.
Incorrect. * allows zero or more characters and would also match report10.csv.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp -d); touch "$tmp/report1.csv" "$tmp/report7.csv" "$tmp/reportA.csv" "$tmp/report10.csv"; (cd "$tmp" && printf '%s\n' report[0-9].csv); rm -rf "$tmp"Expected result
report1.csv
report7.csvKey points
- Brackets form a one-character set
- 0-9 is a digit range
- ! negates a set
Notes
- Environment: 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.