mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2060 (markdown)
@@ -14,7 +14,11 @@ tr -cd '[:digit:]'
|
|||||||
|
|
||||||
### Rationale:
|
### Rationale:
|
||||||
|
|
||||||
`[:digit:]` is a shell glob that matches any single character file named e.g. `g` or `t` in the current directory. Quoting it prevents the script from breaking in directories with files like this.
|
From the shell's point of view, unquoted `[:digit:]` is glob equivalent to `[dgit:]` that matches any single character filename from the group, such as `g` or `t`, in the current directory.
|
||||||
|
|
||||||
|
If someone starts learning D and creates a directory named `d` to hold the source code, the glob will be expanded and the script will end up executing `tr -cd d`, which is clearly unintended.
|
||||||
|
|
||||||
|
Quoting the argument prevents this, and will pass it correctly as the literal string `[:digit:]` no matter which files exist in the current directory.
|
||||||
|
|
||||||
### Exceptions
|
### Exceptions
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user