mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2321 (markdown)
24
SC2321.md
Normal file
24
SC2321.md
Normal file
@@ -0,0 +1,24 @@
|
||||
## Array indices are already arithmetic contexts. Prefer removing the $(( and )).
|
||||
|
||||
### Problematic code:
|
||||
|
||||
```sh
|
||||
values[$((i+1))]=1
|
||||
```
|
||||
|
||||
### Correct code:
|
||||
|
||||
```sh
|
||||
values[i+1]=1
|
||||
```
|
||||
### Rationale:
|
||||
|
||||
In indexed arrays (but not associative ones), the array index is already an arithmetic context. There is no point or value in wrapping it in an additional, explicit `$((..))`.
|
||||
|
||||
### Exceptions:
|
||||
|
||||
If ShellCheck has failed to realize that your array is associative, or if you for stylistic reasons prefer the redundancy, you can ignore this message.
|
||||
|
||||
### Related resources:
|
||||
|
||||
* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!
|
Reference in New Issue
Block a user