From f7cc442af4439d2156b60bc9846cb299dadae687 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 13 Oct 2021 09:27:55 -0700 Subject: [PATCH] lib/utilities: simplify `_bash-it-array-dedup()` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit alsö fix usage example of `_bash-it-array-contains-element()` --- lib/utilities.bash | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/utilities.bash b/lib/utilities.bash index 84fa4d96..9b011910 100644 --- a/lib/utilities.bash +++ b/lib/utilities.bash @@ -40,7 +40,7 @@ function _bash-it-get-component-type-from-path() { # $ _bash-it-array-contains-element apple "@{fruits[@]}" && echo 'contains apple' # contains apple # -# $ if $(_bash-it-array-contains-element pear "${fruits[@]}"); then +# $ if _bash-it-array-contains-element pear "${fruits[@]}"; then # echo "contains pear!" # fi # contains pear! @@ -54,10 +54,9 @@ function _bash-it-array-contains-element() { return 1 } -# Dedupe a simple array of words without spaces. +# Dedupe an array (without embedded newlines). function _bash-it-array-dedup() { - local IFS=$'\n' - echo "$@" | tr ' ' '\n' | sort -u + printf '%s\n' "$@" | sort -u } # Outputs a full path of the grep found on the filesystem