You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Line 3:
GROUPS=$1
^-- SC2178: Variable was used as an array but is now assigned a string.
Line 5:
if [ -n "${GROUPS}" ]; then
^-- SC2128: Expanding an array without an index only gives the first element.
Line 6:
echo "${GROUPS}";
^-- SC2128: Expanding an array without an index only gives the first element.
Here's what I wanted or expected to see:
Something telling me GROUPS is an internal shell variable that is an array, which is why it's telling me this.
It took me a very long time to see that if I renamed the variable, then it stopped badgering me about it, which I was very, very puzzled about. Mostly because FreeBSD's sh, which is the one I am working with, does not have arrays at all.
it took me even longer, mostly by accident, to find out that while FreeBSD's sh did not have an internal variable named GROUPS, bash had one, and it was probably why I was getting the error.
The text was updated successfully, but these errors were encountered:
I also have a worst test-case with $GROUPS which puzzled me recently. Shellcheck doesn't warn about reusing builtin variables leading to completely wrong work.
❯ cat groups.sh
#!/bin/bash
GROUPS=( hurr durr )
for g in "${GROUPS[@]}"; do
echo "$g"
done
/tmp
❯ shellcheck groups.sh; echo $?
0
/tmp
❯ bash groups.sh
2000
6
10
For bugs
shellcheck --version
or "online"): onlineFor new checks and feature suggestions
Here's a snippet or screenshot that shows the problem:
Here's what shellcheck currently says:
Here's what I wanted or expected to see:
Something telling me
GROUPS
is an internal shell variable that is an array, which is why it's telling me this.It took me a very long time to see that if I renamed the variable, then it stopped badgering me about it, which I was very, very puzzled about. Mostly because FreeBSD's sh, which is the one I am working with, does not have arrays at all.
it took me even longer, mostly by accident, to find out that while FreeBSD's sh did not have an internal variable named GROUPS, bash had one, and it was probably why I was getting the error.
The text was updated successfully, but these errors were encountered: