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.
report[0-9].csvCorrect. report[0-9].csv matches one numeric character only.
report[!0-9].csvIncorrect. [!0-9] selects a non-digit, the opposite condition.
report*.csvIncorrect. * 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 / 一時ディレクトリ
- Use disposable files and directories for destructive or timestamp-related checks.
- Command details can vary slightly between GNU and non-GNU implementations.
Foundation review
Place the operation
A digit range is more selective than a question mark, while an asterisk permits multiple characters.
Check the side effect
Include alphabetic and multi-digit names in a temporary test so the length and character restrictions are visible.