Skip to content

Instantly share code, notes, and snippets.

@sirikon
Last active November 12, 2022 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sirikon/df886ddb57d3d16166337ebaf60f7445 to your computer and use it in GitHub Desktop.
Save sirikon/df886ddb57d3d16166337ebaf60f7445 to your computer and use it in GitHub Desktop.
Task file in Bash
#!/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