From a6d76b8fadeb1d3be6f663fbcd3f971a8a8b44c3 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sun, 24 Jul 2022 14:38:53 -0700 Subject: [PATCH] Created SC2322 (markdown) --- SC2322.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 SC2322.md diff --git a/SC2322.md b/SC2322.md new file mode 100644 index 0000000..a330133 --- /dev/null +++ b/SC2322.md @@ -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! \ No newline at end of file