From 80a8e48c1096393f7d5326d90797b79d7909e3b7 Mon Sep 17 00:00:00 2001 From: William Melody Date: Sun, 29 Nov 2015 18:09:35 -0800 Subject: [PATCH] Use `if..then` in `show` to avoid non-zero exits. The `[[ ... ]] && ...` conditional style results in non-zero exits when the test is false. Moving this to a traditional `if..then` style avoids this behavior while also being more explicit about the objective of the code. `|| return 0` or `|| exit 0` could have been added as an alternative way to avoid the non-zero exit behavior, but is not used in this case because the traditional `if..then` style is more common. --- hosts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hosts b/hosts index 6be893f..d487b0b 100755 --- a/hosts +++ b/hosts @@ -1084,8 +1084,14 @@ show() { grep "^[^#]*$1" "${HOSTS_PATH}" ) # Output disabled records secondly for better organization. - [[ -n "$enabled_records" ]] && printf "%s\n" "$enabled_records" - [[ -n "$disabled_records" ]] && printf "%s\n" "$disabled_records" + if [[ -n "$enabled_records" ]] + then + printf "%s\n" "$enabled_records" + fi + if [[ -n "$disabled_records" ]] + then + printf "%s\n" "$disabled_records" + fi else $_ME help show exit 1