Skip to content
Joachim Ansorg edited this page Nov 12, 2021 · 2 revisions

Quote the parameter to -name so the shell won't interpret it.

Problematic code:

find . -name *.txt

Correct code:

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.

ShellCheck

Each individual ShellCheck warning has its own wiki page like SC1000. Use GitHub Wiki's "Pages" feature above to find a specific one, or see Checks.

Clone this wiki locally