mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2101 (markdown)
17
SC2101.md
Normal file
17
SC2101.md
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
# Named class needs outer [], e.g. [[:digit:]].
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
gzip file[:digit:]*.txt
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
gzip file[[:digit:]]*.txt
|
||||||
|
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
Predefined character groups are supposed to be used inside character ranges. `[:digit:]` matches one of "digt:" just like `[abc]` matches one of "abc". `[[:digit:]]` matches a digit.
|
||||||
|
|
||||||
|
### Contraindications
|
||||||
|
|
||||||
|
When passing an argument to `tr` which parses these by itself without relying on globbing, you should quote it instead, e.g. `tr -d '[:digit:]'`
|
Reference in New Issue
Block a user