From 93e96e7289bc1a701dae3529973ce7fa34c8806b Mon Sep 17 00:00:00 2001 From: koalaman Date: Wed, 13 Jan 2016 12:55:51 -0800 Subject: [PATCH] Updated SC2076 (markdown) --- SC2076.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SC2076.md b/SC2076.md index 6ebed34..3e65c63 100644 --- a/SC2076.md +++ b/SC2076.md @@ -3,20 +3,20 @@ ### Problematic code: ```sh -[[ $foo =~ "^fo+bar$" ]] +[[ $foo =~ "^fo+ bar$" ]] ``` ### Correct code: ```sh -[[ $foo =~ ^fo+bar$ ]] +[[ $foo =~ ^fo+\ bar$ ]] ``` ### Rationale: Quotes on the right hand side of `=~` can be used to match literally, so that `[[ $1 =~ ^"$2".* ]]` works even if `$2` contains regex metacharacters. This mirrors the behavior of globs, `[[ $1 = "$2"* ]]`. -This also means that the problematic code tries to match literal carets and plus signs instead of interpreting them as regular expression matchers. To match as a regex, it must be unquoted. +This also means that the problematic code tries to match literal carets and plus signs instead of interpreting them as regular expression matchers. To match as a regex, the regex metacharacters it must be unquoted. Literal parts of the expression can be quoted with double or single quotes, or escaped. ### Exceptions: