From 668f5e9d8f91e78facadf6851cef554b9950a529 Mon Sep 17 00:00:00 2001 From: koalaman Date: Sun, 10 Nov 2013 12:21:32 -0800 Subject: [PATCH] Created Sc2062 (markdown) --- Sc2062.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Sc2062.md diff --git a/Sc2062.md b/Sc2062.md new file mode 100644 index 0000000..43baa72 --- /dev/null +++ b/Sc2062.md @@ -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. \ No newline at end of file