From f0ebb08cd4df636205bef9fa560c6986d0712399 Mon Sep 17 00:00:00 2001 From: William Melody Date: Sun, 7 Jun 2020 13:25:03 -0700 Subject: [PATCH] Use improved `_join()`. --- hosts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/hosts b/hosts index 55e119a..ec1e0b4 100755 --- a/hosts +++ b/hosts @@ -323,19 +323,21 @@ _contains() { # _join() # # Usage: -# _join +# _join "," a b c +# _join "${an_array[@]}" # -# Examples: -# _join , a "b c" d => a,b c,d -# _join / var local tmp => var/local/tmp -# _join , "${FOO[@]}" => a,b,c +# Returns: +# The list or array of items joined into a string with elements divided by +# the optional separator if one is provided. # -# More Information: -# http://stackoverflow.com/a/17841619 +# More information: +# https://stackoverflow.com/a/17841619 _join() { - local IFS="${1}" + local _delimiter="${1}" shift - printf "%s\\n" "${*}" + printf "%s" "${1}" + shift + printf "%s" "${@/#/${_delimiter}}" | tr -d '[:space:]' } # _blank()