Updated SC2155 (markdown)

Vidar Holen
2021-07-25 17:28:44 -07:00
parent 0f153e166d
commit 865736f4cc

@@ -19,16 +19,18 @@ In the original code, the return value of `mycmd` is ignored, and `export` will
When first marked for export and assigned separately, the return value of the assignment will be that of `mycmd`. This avoids the problem. When first marked for export and assigned separately, the return value of the assignment will be that of `mycmd`. This avoids the problem.
Note that ShellCheck does not warn about masking of local read-only variables, such as `local -r foo=$(cmd)`, even though this also masks the return value. This is because the alternative `local foo; foo=$(cmd); local -r foo` is repetitive and cumbersome.
#### Exceptions: #### Exceptions:
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
foo=$(mycmd) || true foo=$(mycmd) || true
export foo 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.
### Problematic code in the case of `local`: ### Problematic code in the case of `local`: