From 22ea7d34bc55bc2d4cda221996af0ed87c49a21a Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 8 Sep 2021 16:09:44 -0700 Subject: [PATCH] lib/utilities: fix `_bash-it-grep()` 1. Executing `'/usr/bin/grep'` does *not* return the path to grep... 2. use `type -p` instead of external binary `which`. 3. Simplify parameter definition. 4. Why was there a space after `%s`? --- lib/utilities.bash | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/utilities.bash b/lib/utilities.bash index 322c9bdf..fa77d4fd 100644 --- a/lib/utilities.bash +++ b/lib/utilities.bash @@ -60,11 +60,10 @@ _bash-it-array-dedup() { } # Outputs a full path of the grep found on the filesystem -_bash-it-grep() { - if [[ -z "${BASH_IT_GREP:-}" ]] ; then - export BASH_IT_GREP="$(which egrep || which grep || '/usr/bin/grep')" - fi - printf "%s " "${BASH_IT_GREP}" +function _bash-it-grep() +{ + : "${BASH_IT_GREP:=$(type -p egrep || type -p grep)}" + printf "%s" "${BASH_IT_GREP:-'/usr/bin/grep'}" }