From 3bc392a6b3de409b8c055ee4f599cc66c9a28bf9 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Tue, 25 Jun 2019 08:38:12 +0200 Subject: [PATCH] functions/__fish_print_hostnames: Check getent's status This previously effectively checked `string split ' '`s return status, which was false if it didn't split anything. And while that should be true if getent fails (because it should produce no output), it's also true if it doesn't print a line with multiple aliases. Which should be fairly typical. Instead we use our new-found $pipestatus to check what getent returns, in the assumption that it'll fail if it doesn't support hosts. Follow up to 8f7a47547e0f8e3055f51dddd59e1cce7bd49618. [ci skip] --- share/functions/__fish_print_hostnames.fish | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/share/functions/__fish_print_hostnames.fish b/share/functions/__fish_print_hostnames.fish index 0d32cb9cf..f4f07690f 100644 --- a/share/functions/__fish_print_hostnames.fish +++ b/share/functions/__fish_print_hostnames.fish @@ -8,7 +8,8 @@ function __fish_print_hostnames -d "Print a list of known hostnames" type -q getent # Ignore zero IPs. and getent hosts 2>/dev/null | string match -r -v '^0.0.0.0' | string replace -r '^\s*\S+\s+' '' | string split ' ' - or if test -r /etc/hosts + # We care about _getent_s status, not `string split`s. + if test $pipestatus[1] -ne 0; and test -r /etc/hosts # Ignore commented lines and functionally empty lines. string match -r -v '^\s*0.0.0.0|^\s*#|^\s*$'