Skip to content

Files

Latest commit

 

History

History
45 lines (29 loc) · 1.05 KB

SC2163.md

File metadata and controls

45 lines (29 loc) · 1.05 KB

Pattern: Use of export with expanded variable

Issue: -

Description

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

Exceptions

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.

Further Reading