Skip to content

Multiple issues on Bash with declare -n #3380

@S4mu3LJ3f

Description

@S4mu3LJ3f

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

#!/bin/bash
declare i=0
declare -A arr_123=()
declare -n arr=arr_123

arr+=([${i}]="$i")
echo "${arr[${i}]}"

Here's what shellcheck currently says:

In test.sh line 4:
declare -A arr_123=()
           ^-----^ SC2034 (warning): arr_123 appears unused. Verify use (or export if used externally).

In test.sh line 7:
arr+=([${i}]="$i")
       ^--^ SC2004 (style): $/${} is unnecessary on arithmetic variables.

And when I change to just [i] behavior changes too.

Also I have issue with SC2178 on declare -n that I can't reproduce in test script for now.

In scr line 895:
    declare -n array_inscr="array_inscr_${i}"   # Array was declared with `-a`
               ^---------^ SC2178 (warning): Variable was used as an array but is now assigned a string.

Here's what I wanted or expected to see:

No warnings when used without a reference.

#!/bin/bash
declare i=0
declare -A arr_123=()
#declare -n arr=arr_123

arr_123+=([${i}]="$i")
echo "${arr_123[${i}]}"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions