Skip to content
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

False positive on SC2191 when using += assignment operator #3110

Open
2 tasks done
Xophmeister opened this issue Dec 31, 2024 · 0 comments
Open
2 tasks done

False positive on SC2191 when using += assignment operator #3110

Xophmeister opened this issue Dec 31, 2024 · 0 comments

Comments

@Xophmeister
Copy link

For bugs

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

#!/usr/bin/bash

x=(foo bar [1]+=quux)
echo "${x[@]}"

Here's what shellcheck currently says:

In - line 3:
x=(foo bar [1]+=quux)
               ^---^ SC2191 (warning): The = here is literal. To assign by index, use ( [index]=value ) with no spaces. To keep as literal, quote it.

Did you mean:
x=(foo bar [1]+"=quux")

For more information:
  https://www.shellcheck.net/wiki/SC2191 -- The = here is literal. To assign ...

Here's what I wanted or expected to see:

This shouldn't trigger SC2191.

Note: Only the += operator works in this context, even with typeset -i; ++ and -= trigger syntax errors in Bash, whereas --, *= and /= get interpreted as literals.

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