24 lines
737 B
Bash
24 lines
737 B
Bash
#!/usr/bin/env bash
|
|
|
|
##
|
|
# description: executes command(s), while checking if the command(s) exist on the system!
|
|
# usage: executeCommand "command1; command2; command3; ..."
|
|
##
|
|
function executeCommand() {
|
|
command=$1
|
|
|
|
command_array=("${(s/;/)command}")
|
|
for cmd in ${command_array[@]}; do
|
|
cmd=${cmd# }
|
|
if ! command -v $(echo $cmd | awk '{print $1}') &> /dev/null; then
|
|
log e "$(echo $cmd | awk '{print $1}') could not be found on this system!"
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
log d "Executing $command"
|
|
"$dryrun" && log i "Would've executed: '$command'" || eval "$command"
|
|
if [[ "$dryrun" = false && $? -eq 0 ]]; then
|
|
log s "Successfully executed: $command"
|
|
fi
|
|
}
|