From 26b6a5d3340fa61407f8762b50807e575926be31 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sun, 24 Jul 2022 14:54:35 -0700 Subject: [PATCH] Created SC2323 (markdown) --- SC2323.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 SC2323.md diff --git a/SC2323.md b/SC2323.md new file mode 100644 index 0000000..695c47b --- /dev/null +++ b/SC2323.md @@ -0,0 +1,32 @@ +## `a[(x)]` is the same as `a[x]`. Prefer not wrapping in additional parentheses. + +Similarly `$(( (x) ))` is the same as `$(( x ))`, `(( (x) ))` is the same as `(( x ))`. + + +### Problematic code: + +```sh +array[(x+1)]=val +echo $(( (x+1) )) +``` + +### Correct code: + +```sh +array[x+1]=val +echo $((x+1)) +``` + +### Rationale: + +ShellCheck found an entire arithmetic expression wrapped in parentheses. This does not serve a purpose since the expression is already clearly delimited by the construct it's in, such as `array[..]=` or `$((..))` in the example. + +Note: ShellCheck does *not* warn about redundant parentheses in subexpressions, such as `(a*b)+c`. Feel free to use parentheses to clarify the order of operations any way you'd like. ShellCheck only emits this suggestion when the *entire* expression is wrapped *twice*. + +### Exceptions: + +If you prefer having an extra layer of parentheses for stylistic reasons, you can [[ignore]] this message. + +### Related resources: + +* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc! \ No newline at end of file