Skip to content

array-without-index

Shellcorrectnessno fixdefault: offshell/shellcheck

Reports $BASH_SOURCE, $FUNCNAME and the other bash arrays used without a subscript.

$BASH_SOURCE is the same as ${BASH_SOURCE[0]}: the first element only. A reader may expect the whole array or the top of the stack, and the code is wrong when the element that was meant is another one.

To fix, write the subscript: ${BASH_SOURCE[0]}.

Reported
...
A=1 cmd "$B"
A=1 cmd "$A_"
echo "$FUNCNAME" "${FUNCNAME[0]}"
shell:
lint:
rules:
array-without-index: warn # off (default), warn, error

Enabled by the presets: shell/shellcheck.

Suppress one line with sudsy-disable-next-line array-without-index in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
shellcheck SC2128 partial Only the bash arrays BASH_SOURCE, FUNCNAME and the like; user arrays need their declarations.