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