Skip to content

SC2030/SC2031 and `declare -p' #540

@admirabilis

Description

@admirabilis

While SC2030 and SC2031 warn against modified variables inside a subshell, the option -p for declare is used only to print the attributes of a variable, not to modify it:

$ help declare | grep -- -p
declare: declare [-aAfFgilrtux] [-p] [name[=value] ...]
      -p    display the attributes and value of each NAME

For this script

#!/bin/bash

list=(*)
: "$(declare -p list)"
: "$list"

shellcheck returns

In /tmp/1 line 4:
: "$(declare -p list)"
                ^-- SC2030: Modification of list is local (to subshell caused by $(..) expansion).

In /tmp/1 line 5:
: "$list"
   ^-- SC2031: list was modified in a subshell. That change might be lost.

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