mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2155 (markdown)
@@ -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.
|
||||
|
||||
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:
|
||||
|
||||
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
|
||||
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.
|
||||
|
||||
### Problematic code in the case of `local`:
|
||||
|
||||
|
Reference in New Issue
Block a user