mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2004 (markdown)
@@ -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'
|
||||
|
Reference in New Issue
Block a user