Created SC2061 (markdown)

koalaman
2015-11-06 09:48:42 -08:00
parent 59d27ae0d9
commit 1b9d2d75ec

26
SC2061.md Normal file

@@ -0,0 +1,26 @@
## Quote the parameter to -name so the shell won't interpret it.
### Problematic code:
```sh
find . -name *.txt
```
### Correct code:
```sh
find . -name '*.txt'
```
### Rationale:
Several find options take patterns to match against, including `-ilname`, `-iname`, `-ipath`, `-iregex`, `-iwholename`, `-lname`, `-name`, `-path`, `-regex` and `-wholename`.
These compete with the shell's pattern expansion, and must therefore be quoted so that they are passed literally to `find`.
The example command may end up executing as `find . -name README.txt` after the shell has replaced the `*.txt` with a matching file `README.txt` from the current directory.
This may happen today or suddenly in the future.
### Exceptions:
None.