mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2322 (markdown)
24
SC2322.md
Normal file
24
SC2322.md
Normal file
@@ -0,0 +1,24 @@
|
||||
## In arithmetic contexts, ((x)) is the same as (x). Prefer only one layer of parentheses.
|
||||
|
||||
### Problematic code:
|
||||
|
||||
```sh
|
||||
value=$(( ((offset + index)) * 512 ))
|
||||
```
|
||||
|
||||
### Correct code:
|
||||
|
||||
```sh
|
||||
value=$(( (offset + index) * 512 ))
|
||||
```
|
||||
### Rationale:
|
||||
|
||||
ShellCheck found doubly nested parentheses in an arithmetic expression. While the syntax for an arithmetic expansion is `$((..))`, this does not imply that parentheses in the expression should also be doubled. `(x)`, `((x))`, and `(((x)))` are all identical, so you might as well use only one layer of parentheses.
|
||||
|
||||
### Exceptions:
|
||||
|
||||
This is a stylistic suggestion. If you prefer keeping both parentheses, 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