Skip to content
Vidar Holen edited this page Jul 24, 2022 · 1 revision

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:

array[(x+1)]=val
echo $(( (x+1) ))

Correct code:

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!

ShellCheck

Each individual ShellCheck warning has its own wiki page like SC1000. Use GitHub Wiki's "Pages" feature above to find a specific one, or see Checks.

Clone this wiki locally