mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 11:19:45 +08:00
Provide rationale for SC2155 in the case of local
as explained by @jgallag88 in delphix/appliance-build#339
10
SC2155.md
10
SC2155.md
@@ -43,6 +43,16 @@ local foo
|
||||
foo=$(mycmd)
|
||||
```
|
||||
|
||||
### Rationale
|
||||
|
||||
The exit status of the command is overridden by the exit status of the creation the local variable. For example:
|
||||
|
||||
```bash
|
||||
$ f() { local foo=$(false) || echo foo; }; f
|
||||
$ f() { local foo; foo=$(false) || echo foo; }; f
|
||||
foo
|
||||
```
|
||||
|
||||
### Problematic code in the case of `readonly`:
|
||||
|
||||
```sh
|
||||
|
Reference in New Issue
Block a user