Last active
June 18, 2025 01:03
-
-
Save mamemomonga/60ea97b9bb916cda9595da36ae0542cd to your computer and use it in GitHub Desktop.
簡易メニューシェルスクリプト。do_* というfunctionの*部分を引数に指定して実行できる。
This file contains hidden or 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
#!/bin/bash | |
set -eu | |
do_cmd1() { | |
echo "cmd1" | |
} | |
do_cmd2() { | |
echo "cmd2" | |
} | |
# ------------------------------------------------- | |
COMMAND_LISTS=$(declare -F | awk '{ print $3 }' | grep -e '^do_') | |
usage() { | |
echo "USAGE: $0 [COMMAND]" | |
echo " COMMANDS:" | |
for i in $COMMAND_LISTS; do | |
echo " ${i#do_}" | |
done | |
exit 1 | |
} | |
if [ -z "${1:-}" ]; then usage; fi | |
for i in $COMMAND_LISTS; do | |
if [ "${i#do_}" == "$1" ]; then | |
"$i" | |
exit 0 | |
fi | |
done | |
usage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment