mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2163 (markdown)
13
SC2163.md
13
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.
|
Reference in New Issue
Block a user