From f910995c0b110c8e718fce6f7ca4dcdd7ba41ad4 Mon Sep 17 00:00:00 2001 From: Kevin Brubeck Unhammer Date: Sat, 24 Oct 2020 09:20:18 +0200 Subject: [PATCH] Note about exit code --- SC2005.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/SC2005.md b/SC2005.md index 794e03a..95fd2b2 100644 --- a/SC2005.md +++ b/SC2005.md @@ -18,7 +18,9 @@ cat 1.txt # In bash, but faster and still sticks exactly one newline: printf '%s ### Rationale -The command substitution `$(foo)` yields the result of command `foo` with trailing newlines erased, and when it is passed to `echo` it generally just gives the same result as `foo`. +The command substitution `$(foo)` yields the result of command `foo` with trailing newlines erased, and when it is passed to `echo` it generally just gives the same result as `foo`. + +The command `echo "$(false)"` will return true, whereas `false` of course returns false – beware of the ignored exit code before blindly altering scripts. If using `set -e`, the correct substitution of `echo "$(cmd)"` would be `cmd || true`. ### Exceptions