From 6c3a02fc5f6f05cd7082e0049d19b97e2e74bb48 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Thu, 8 Nov 2018 08:32:34 +0800 Subject: [PATCH] Updated SC2004 (markdown) --- SC2004.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SC2004.md b/SC2004.md index 1ebfe7c..c5a7941 100644 --- a/SC2004.md +++ b/SC2004.md @@ -3,18 +3,18 @@ ### Problematic code: ```sh -echo $(($n+1)) +echo $(($n + ${arr[i]})) ``` ### Correct code: ```sh -echo $((n+1)) +echo $((n + arr[i])) ``` ### Rationale: -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 `$` or `${..}` 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: ```sh $ a='1+1'