Skip to content

Commit

Permalink
src: kwlib: improve command_exists check
Browse files Browse the repository at this point in the history
Use only the first "word" from a command line to check if the command
exists or not.

Reviewed-by: Rodrigo Siqueira <siqueirajordao@riseup.net>
Signed-off-by: Rubens Gomes Neto <rubens.gomes.neto@usp.br>
  • Loading branch information
kwy95 authored and rodrigosiqueira committed Jan 22, 2022
1 parent 05e40a5 commit 8076ae1
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/kwlib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,12 @@ function store_statistics_data()
function command_exists()
{
local command="$1"
#shellcheck disable=SC2206 #FIXME: see issue #388
local package=($command)
local package=${command%% *}

if [[ -x "$(command -v "${package[@]}")" ]]; then
return 0
if [[ ! -x "$(command -v "$package")" ]]; then
return 22 # EINVAL
fi
return 22 # EINVAL
return 0
}

# This function exits with a custom error message
Expand Down

0 comments on commit 8076ae1

Please sign in to comment.