From 1946836564d01b69fcd4fbc7d38c79da787dcbe8 Mon Sep 17 00:00:00 2001 From: koalaman Date: Sat, 1 Mar 2014 16:31:59 -0800 Subject: [PATCH] Created SC2022 (markdown) --- SC2022.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 SC2022.md diff --git a/SC2022.md b/SC2022.md new file mode 100644 index 0000000..6ec4dcb --- /dev/null +++ b/SC2022.md @@ -0,0 +1,23 @@ +# Note that c* does not mean "c followed by anything" in regex. + +### Problematic code: + + grep 'foo*' + +when wanting to match `food` and `foosball`, but not `mofo` or `keyfob`. + +### Correct code: + + grep '^foo' + +### Rationale: + +As a glob, `foo*` means "Any string starting with foo", e.g. `food` and `foosball`. + +As a regular expression, "foo*" means "f followed by 1 or more o's, anywhere", e.g. "mofo" or "keyfob". + +This construct is way more common as a glob than as a regex, so ShellCheck notifies you about it. + +### Contraindications + +If you're aware of the above, you can ignore this message. If you'd like shellcheck to be quiet, use a [[directive]] or `'fo[o]*'`. \ No newline at end of file