From 93d4e6f5d90d181597f153ebaa45ed7866d65382 Mon Sep 17 00:00:00 2001 From: Mingye Wang Date: Tue, 12 May 2020 12:50:30 +0800 Subject: [PATCH] Updated SC2155 (markdown) --- SC2155.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/SC2155.md b/SC2155.md index 11a7e74..efb0d7d 100644 --- a/SC2155.md +++ b/SC2155.md @@ -6,20 +6,20 @@ export foo="$(mycmd)" ``` -### Correct code: +#### Correct code: ```sh foo="$(mycmd)" export foo ``` -### Rationale: +#### Rationale: In the original code, the return value of `mycmd` is ignored, and `export` will instead always return true. This may prevent conditionals, `set -e` and traps from working correctly. When first marked for export and assigned separately, the return value of the assignment will be that of `mycmd`. This avoids the problem. -### Exceptions: +#### Exceptions: If you intend to ignore the return value of an assignment, you can either ignore this warning or use @@ -36,14 +36,14 @@ Shellcheck does not warn about `export foo=bar` because `bar` is a literal and n local foo="$(mycmd)" ``` -### Correct code: +#### Correct code: ```sh local foo foo=$(mycmd) ``` -### Rationale +#### Rationale The exit status of the command is overridden by the exit status of the creation of the local variable. For example: @@ -59,14 +59,14 @@ foo readonly foo="$(mycmd)" ``` -### Correct code: +#### Correct code: ```sh foo="$(mycmd)" readonly foo ``` -### Word splitting and quoting issue with dash, maybe others +#### Word splitting and quoting issue with dash, maybe others A serious quoting problem with dash is another reason to declare and assign separately. Dash is the [default, `/bin/sh` shell on Ubuntu](https://wiki.ubuntu.com/DashAsBinSh). More specifically, dash version 0.5.8-2.10 and others cannot run this code: ```sh