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.
While SC2030 and SC2031 warn against modified variables inside a subshell, the option
-pfordeclareis used only to print the attributes of a variable, not to modify it:For this script
shellcheck returns