mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Avoid exporting empty env
@@ -9,8 +9,8 @@ export foo="$(mycmd)"
|
|||||||
### Correct code:
|
### Correct code:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
export foo
|
|
||||||
foo=$(mycmd)
|
foo=$(mycmd)
|
||||||
|
export foo
|
||||||
```
|
```
|
||||||
|
|
||||||
### Rationale:
|
### Rationale:
|
||||||
@@ -24,8 +24,8 @@ When first marked for export and assigned separately, the return value of the as
|
|||||||
If you intend to ignore the return value of an assignment, you can either ignore this warning or use
|
If you intend to ignore the return value of an assignment, you can either ignore this warning or use
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
export foo
|
|
||||||
foo=$(mycmd) || true
|
foo=$(mycmd) || true
|
||||||
|
export foo
|
||||||
```
|
```
|
||||||
|
|
||||||
Shellcheck does not warn about `export foo=bar` because `bar` is a literal and not a command substitution with an independent return value. It also does not warn about `local -r foo=$(cmd)`, where declaration and assignment must be in the same command.
|
Shellcheck does not warn about `export foo=bar` because `bar` is a literal and not a command substitution with an independent return value. It also does not warn about `local -r foo=$(cmd)`, where declaration and assignment must be in the same command.
|
||||||
|
Reference in New Issue
Block a user