From f0730898203e7a8dabc0227cb6b324efe61f87a0 Mon Sep 17 00:00:00 2001 From: Dimitry Ishenko Date: Thu, 22 Dec 2022 10:38:43 -0500 Subject: [PATCH] check.sh: clean up --- src/check.sh | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/check.sh b/src/check.sh index 2b7c1eb..2e51eed 100644 --- a/src/check.sh +++ b/src/check.sh @@ -6,29 +6,27 @@ # @description Check if the command exists in the system. # # @example -# check::command_exists "tput" +# check::command_exists "tput" && echo "yes" || echo "no" # # @arg $1 string Command name to be searched. # -# @exitcode 0 If the command exists. -# @exitcode 1 If the command does not exist. +# @exitcode 0 If the command exists. +# @exitcode 1 If the command does not exist. # @exitcode 2 Function missing arguments. check::command_exists() { - [[ $# = 0 ]] && printf "%s: Missing arguments\n" "${FUNCNAME[0]}" && return 2 + (( $# == 0 )) && { printf "%s: Missing arguments\n" "${FUNCNAME[0]}"; return 2; } hash "${1}" 2> /dev/null } -# @description Check if the script is executed with sudo privilege. +# @description Check if the script is running with root privileges. # # @example -# check::is_sudo +# check::is_sudo && echo "yes" || echo "no" # # @noargs # -# @exitcode 0 If the script is executed with root privilege. -# @exitcode 1 If the script is not executed with root privilege +# @exitcode 0 If the script is executed with root privilege. +# @exitcode 1 If the script is not executed with root privilege check::is_sudo() { - if [[ $(id -u) -ne 0 ]]; then - return 1 - fi + (( $(id -u) == 0 )) && return 0 || return 1 }