Updated SC2155 (markdown)

Léo Andrès
2018-02-23 01:35:17 +01:00
parent 6d3e778e76
commit 2ea4bed1c1

@@ -1,6 +1,6 @@
## Declare and assign separately to avoid masking return values. ## Declare and assign separately to avoid masking return values.
### Problematic code: ### Problematic code in the case of `export`:
```sh ```sh
export foo="$(mycmd)" 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. 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)
```