mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Not confident with the rationale but the page was blank
20
SC2010.md
Normal file
20
SC2010.md
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
## Don't use ls | grep. Use a glob or a for loop with a condition to allow non-alphanumeric filenames.
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
ls /directory | grep target_file_pattern
|
||||||
|
```
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
ls /directory/target_file_pattern
|
||||||
|
```
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
Matching non-alphanumeric characters with grep may require escaping. Typically it is cleaner to use the built in pattern matching or another command like `find`
|
||||||
|
|
||||||
|
### Exceptions:
|
||||||
|
|
||||||
|
None
|
Reference in New Issue
Block a user