koalaman / shellcheck

ShellCheck, a static analysis tool for shell scripts

Home Page:https://www.shellcheck.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SC2004 false positive on assignment to array position

partcyborg opened this issue · comments

For bugs

Here's a snippet or screenshot that shows the problem:

NOTE: this is the simplest test case I could think of. Real world use case is more involved.

#!/bin/bash
declare -a foo=()
i=0
foo[$i]=bar
echo "${foo[@]}"

Here's what shellcheck currently says:

foo[$i]=bar
    ^-- SC2004 (style): $/${} is unnecessary on arithmetic variables.

Here's what I wanted or expected to see:

The checks should pass, as there is no arithmetic involved, nor is there a code syntax issue.

Nevermind, I did not realize $ wasn't necessary in arrays