diff --git a/SC2163.md b/SC2163.md index b47bc68..9c5cc0b 100644 --- a/SC2163.md +++ b/SC2163.md @@ -1,4 +1,4 @@ -## Exporting an expansion rather than a variable. +## This does not export 'FOO'. Remove $/${} for that, or use ${var?} to quiet. ### Problematic code: @@ -20,9 +20,18 @@ export MYVAR ### Exceptions: -If you do want to export the variable's value, e.g. due to indirection, you can disable this message with a directive: +If this is intentional and you do want to export `foo` instead of `MYVAR`, you can either use a directive: ```sh # shellcheck disable=SC2163 export "$MYVAR" ``` + +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: + +```sh +export "${MYVAR}" # ShellCheck warns +export "${MYVAR?}" # No warning +``` + +`${MYVAR?}` fails when `MYVAR` is unset, which is fine since `export` would have failed too. The main side effect is an improved runtime error message in that case. \ No newline at end of file