mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2155 (markdown)
15
SC2155.md
15
SC2155.md
@@ -1,6 +1,6 @@
|
||||
## Declare and assign separately to avoid masking return values.
|
||||
|
||||
### Problematic code:
|
||||
### Problematic code in the case of `export`:
|
||||
|
||||
```sh
|
||||
export foo="$(mycmd)"
|
||||
@@ -29,3 +29,16 @@ 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.
|
||||
|
||||
### Problematic code in the case of `local`:
|
||||
|
||||
```sh
|
||||
local foo="$(mycmd)"
|
||||
```
|
||||
|
||||
### Correct code:
|
||||
|
||||
```sh
|
||||
local foo
|
||||
foo=$(mycmd)
|
||||
```
|
Reference in New Issue
Block a user