Last active
November 12, 2022 20:32
-
-
Save sirikon/df886ddb57d3d16166337ebaf60f7445 to your computer and use it in GitHub Desktop.
Task file in Bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
commands=( | |
salute | |
) | |
function salute {( | |
echo "Hello ${1}!" | |
)} | |
function help { | |
printf "%s\n" "Available commands:" | |
printf " %s\n" "${commands[@]}" help | |
} | |
function run-command { | |
command="$1" | |
for c in "${commands[@]}"; do | |
if [ "$c" = "$command" ]; then | |
("$command" "${@:2}") | |
return | |
fi | |
done | |
printf "%s\n" "Command '${command}' does not exist." | |
} | |
set -euo pipefail | |
cd "$(dirname "${BASH_SOURCE[0]}")" | |
[ -z "${1:-""}" ] || [ "${1:-""}" = "help" ] && help && exit 0 | |
run-command "${1}" "${@:2}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment