From fd49c9e953c8f9f6c9e558000018ac645b7fa9bf Mon Sep 17 00:00:00 2001 From: Bryan Joshua Pedini Date: Sat, 28 Oct 2023 22:00:06 +0200 Subject: [PATCH] added sudo command not existent error handling --- pman.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pman.sh b/pman.sh index 13d3355..ed368ad 100755 --- a/pman.sh +++ b/pman.sh @@ -78,9 +78,14 @@ elif [ "$more_arguments" = "true" ]; then exit 1 fi -# If sudo is needed and necessary (and installed), prepend it -if [ "$su_needed" = "true" ] && [ "$UID" != 0 ] && command -v "sudo" &>/dev/null; then - sudo $command $command_args "${@}" +# If sudo is needed and necessary (and installed), prepend it, if not installed throw error +if [ "$su_needed" = "true" ] && [ "$UID" != 0 ]; then + if command -v "sudo" &>/dev/null; then + sudo $command $command_args "${@}" + else + echo "sudo command needed but not found" > /dev/stderr + exit 1 + fi else $command $command_args "${@}" fi