mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created Sc2062 (markdown)
12
Sc2062.md
Normal file
12
Sc2062.md
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# Quote the grep pattern so the shell won't interpret it.
|
||||||
|
|
||||||
|
### Problematic code
|
||||||
|
grep foo* file
|
||||||
|
|
||||||
|
### Correct code
|
||||||
|
grep "foo*" file
|
||||||
|
|
||||||
|
### Rationale
|
||||||
|
The regex passed to grep frequently contains characters that collide with globs. The code above is supposed to match "f followed by 1 or more o's", but if the directory contains a file called "foo.txt", an unquoted pattern will cause it to become `grep foo.txt file`.
|
||||||
|
|
||||||
|
To prevent this, always quote the regex passed to grep, especially when it contains one or more glob character.
|
Reference in New Issue
Block a user