From 9287ec9bc751692b099bf10f720813b657efd3eb Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Thu, 25 Jul 2019 12:02:48 -0700 Subject: [PATCH] Provide rationale for SC2155 in the case of `local` as explained by @jgallag88 in delphix/appliance-build#339 --- SC2155.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/SC2155.md b/SC2155.md index b445f17..4ac4324 100644 --- a/SC2155.md +++ b/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