Skip to content

False positive for SC2034; triggers when variable only used in "unset" command #3379

@slycordinator

Description

@slycordinator

For bugs with existing features

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

#!/bin/bash

array=( foo bar baz )
del_index=1
unset 'array[del_index]'
for index in "${!array[@]}"; do
    echo "$index: ${array[$index]}"
done

Here's what shellcheck currently says:

Line 4:
del_index=1
^-- SC2034 (warning): del_index appears unused. Verify use (or export if used externally).

Here's what I wanted or expected to see:

(no output)

Note:
The erroneous warning is shown when I use either of:
unset 'array[del_index]'
unset 'array[$del_index]'

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