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

SC1087 misapplied with declare -n #2526

Open
3 tasks done
keyandthegate opened this issue Jul 7, 2022 · 0 comments
Open
3 tasks done

SC1087 misapplied with declare -n #2526

keyandthegate opened this issue Jul 7, 2022 · 0 comments

Comments

@keyandthegate
Copy link

keyandthegate commented Jul 7, 2022

For bugs

SC1087 check does not allow dynamic variables #640 is related but this seems more reasonable as an exception when using declare -n.

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

#!/bin/bash

declare -A array=()
# shellcheck disable=SC2034 # Used through declare -n
array[key]=value
variable_name=array
declare -n variable="$variable_name[key]"
echo "$variable"

Here's what shellcheck currently says:

Line 7:
declare -n variable="$variable_name[key]"
                     ^-- SC1087 (error): Use braces when expanding arrays, e.g. ${array[idx]} (or ${var}[.. to quiet).

Here's what I wanted or expected to see:

No error.

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