From 048b94f5794fa2a46520e4224b73753ec585508a Mon Sep 17 00:00:00 2001 From: koalaman Date: Mon, 11 Jan 2016 11:56:37 -0800 Subject: [PATCH] Created SC2053 (markdown) --- SC2053.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 SC2053.md diff --git a/SC2053.md b/SC2053.md new file mode 100644 index 0000000..f7daaa0 --- /dev/null +++ b/SC2053.md @@ -0,0 +1,24 @@ +## Quote the rhs of = in [[ ]] to prevent glob matching. + +### Problematic code: + +```sh +[[ $a = $b ]] +``` + +### Correct code: + +```sh +[[ $a = "$b" ]] +``` +### Rationale: + +When the right-hand side of `=`, `==` or `!=` is unquoted in `[[ .. ]]`, it will be treated like a glob. + +This has some unexpected consequences like `[[ $var = $var ]]` being false (for `var='[a]'`), or `[[ $foo = $bar ]]` giving a different result from `[[ $bar = $foo ]]`. + +The most common intention is to compare one variable to another as strings, in which case the right-hand side must be quoted. + +### Exceptions: + +If you explicitly want to match against a pattern, you can [[ignore]] this warning. \ No newline at end of file