From 1ad781919689c0bb7d30fe66782b53742c381183 Mon Sep 17 00:00:00 2001 From: koalaman Date: Thu, 29 Dec 2016 14:44:21 -0800 Subject: [PATCH] Created SC2193 (markdown) --- SC2193.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 SC2193.md diff --git a/SC2193.md b/SC2193.md new file mode 100644 index 0000000..c506c7b --- /dev/null +++ b/SC2193.md @@ -0,0 +1,28 @@ +## The arguments to this comparison can never be equal. Make sure your syntax is correct. + +### Problematic code: + +```sh +[[ "{$var}" == "value" ]] # Swapped around $ and { +[[ "$(cmd1) | cmd2" == "42" ]] # Ended with ) too soon +[[ "$var " == *.png ]] # Trailing space +``` + +### Correct code: + +```sh +[[ "${var}" == "value" ]] # Correct variable expansion +[[ "$(cmd1 | cmd2)" == "42" ]] # Correct command substitution +[[ "$var" == *.png ]] # No trailing space +``` +### Rationale: + +ShellCheck has determined that the two values you're comparing can never be equal. + +Most of the time, this happens because of a syntax issue that introduced unintended literal characters into one of the arguments. + +The left-hand side in the problematic examples will always contain (respectively) curly braces, pipe and trailing space. The right-hand sides are literal values and a pattern without trailing spaces, so they will never be equal. The statement is therefore useless, strongly indicating a bug. + +### Exceptions: + +None. \ No newline at end of file