Skip to content

SC2004: false positive on associative arrays used inside (()) #3208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task done
Yrahcaz7 opened this issue May 20, 2025 · 0 comments
Open
1 task done

SC2004: false positive on associative arrays used inside (()) #3208

Yrahcaz7 opened this issue May 20, 2025 · 0 comments

Comments

@Yrahcaz7
Copy link

Yrahcaz7 commented May 20, 2025

For bugs

  • Rule Id: SC2004
  • My shellcheck version: online
  • I tried on shellcheck.net and verified that this is still a problem on the latest commit

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

#!/usr/bin/env bash

char="-"
value=10

readonly -A CHAR_VALUES=(["+"]=1 ["-"]=2 ["|"]=3)
(( value += CHAR_VALUES[$char] ))

Here's what shellcheck currently says:

[Line 7:](javascript:setPosition(7, 25))
(( value += CHAR_VALUES[$char] ))
                        ^-- [SC2004](https://www.shellcheck.net/wiki/SC2004) (style): $/${} is unnecessary on arithmetic variables.

Here's what I wanted or expected to see:

Nothing, as removing the $ changes the meaning of the expression.

Note: If $char is changed to "$char", shellcheck no longer complains.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant