added sudo command not existent error handling

This commit is contained in:
Bryan Joshua Pedini 2023-10-28 22:00:06 +02:00
parent eeaee974bd
commit fd49c9e953

View File

@ -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
# 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