Skip to content

Files

Latest commit

 

History

History
21 lines (11 loc) · 649 Bytes

SC2062.md

File metadata and controls

21 lines (11 loc) · 649 Bytes

Pattern: Use of unquoted grep pattern

Issue: -

Description

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.

Example of incorrect code:

grep foo* file

Example of correct code:

grep "foo*" file

Further Reading