mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Note about exit code
@@ -20,6 +20,8 @@ cat 1.txt # In bash, but faster and still sticks exactly one newline: printf '%s
|
||||
|
||||
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
|
||||
|
||||
One may want to use command substitutions plus `echo` to make sure there is exactly one trailing newline. The special command substitution `$(<file)` in `bash` is also un-outline-able.
|
||||
|
Reference in New Issue
Block a user