From 1e39ff2b3ae00cc571d70cdc8648188e12cab6fa Mon Sep 17 00:00:00 2001 From: koalaman Date: Sun, 16 Mar 2014 14:44:01 -0700 Subject: [PATCH] Created SC2072 (markdown) --- SC2072.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 SC2072.md diff --git a/SC2072.md b/SC2072.md new file mode 100644 index 0000000..6c52201 --- /dev/null +++ b/SC2072.md @@ -0,0 +1,18 @@ +## Decimals are not supported. Either use integers only, or use bc or awk to compare. + +### Problematic code: + + [[ 2 -lt 3.14 ]] + +### Correct code: + + [[ 200 -lt 314 ]] # Use fixed point math + [[ $(echo "2 < 3.14" | bc) == 1 ]] # Use bc + +### Rationale: + +Bash and Posix sh does not support decimals in numbers. Decimals should either be avoided, or compared using a tool that does support them. + +### Contraindications + +If the strings happen to be version numbers and you're using `<`, or `>` to compare them as strings, and you consider this an acceptable thing to do, then you can ignore this warning. \ No newline at end of file