Updated SC2004 (markdown)

Vidar Holen
2018-11-08 08:32:34 +08:00
parent cb26ccff7b
commit 6c3a02fc5f

@@ -3,18 +3,18 @@
### Problematic code: ### Problematic code:
```sh ```sh
echo $(($n+1)) echo $(($n + ${arr[i]}))
``` ```
### Correct code: ### Correct code:
```sh ```sh
echo $((n+1)) echo $((n + arr[i]))
``` ```
### Rationale: ### 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 ```sh
$ a='1+1' $ a='1+1'