From 5ab13325fd5eefd274168021a2e936ab7be535a0 Mon Sep 17 00:00:00 2001 From: koalaman Date: Thu, 17 Sep 2015 13:09:50 -0700 Subject: [PATCH] Updated Sc2004 (markdown) --- Sc2004.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sc2004.md b/Sc2004.md index 1f8de54..46fd7f5 100644 --- a/Sc2004.md +++ b/Sc2004.md @@ -10,6 +10,12 @@ ### Rationale: -The `$` on regular variables in arithmetic contexts has no purpose, and is just noise. +The `$` on regular variables in arithmetic contexts is unnecessary, and can even lead to subtle bugs. This is because the contents of `$((..))` is first expanded into a string, and then evaluated as an expression: -The `$` does matter for special variables like `$1` vs `1`, `$#` vs `#`. ShellCheck does not produce this style suggestion for these cases. \ No newline at end of file + $ a='1+1' + $ echo $(($a * 5)) # becomes 1+1*5 + 6 + $ echo $((a * 5)) # evaluates as (1+1)*5 + 10 + +The `$` is unavoidable for special variables like `$1` vs `1`, `$#` vs `#`. ShellCheck does not warn about these cases. \ No newline at end of file