Pattern: Use of export
with expanded variable
Issue: -
export
takes a variable name, but shellcheck has noticed that you give it an expanded variable instead.
Example of incorrect code:
SOMEVAR=foo
export $SOMEVAR
This does not export SOMEVAR
but a variable called foo
if any.
Example of correct code:
SOMEVAR=foo
export SOMEVAR
If this is intentional and you do want to export foo
instead of SOMEVAR
, you can either use a directive:
# shellcheck disable=SC2163
export "$SOMEVAR"
Or after (but not including) version 0.4.7, take advantage of the fact that ShellCheck only warns when no parameter expansion modifiers are applied:
export "${SOMEVAR}" # ShellCheck warns
export "${SOMEVAR?}" # No warning
${SOMEVAR?}
fails when SOMEVAR
is unset, which is fine since export
would have failed too. The main side effect is an improved runtime error message in that case.