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.
This commit is contained in:
William Melody 2015-11-29 18:09:35 -08:00
parent 4d1adbdf52
commit 80a8e48c10
1 changed files with 8 additions and 2 deletions

10
hosts
View File

@ -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