-
-
Save d630/23928b057cc7feb83a989486ab8c5e3e to your computer and use it in GitHub Desktop.
bash bash 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 | |
myscript () { | |
typeset a i k; | |
# setup cmd; declare functions | |
for i in "${!g_@}"; do | |
typeset -n j=$i; | |
typeset "action_${!j}"; | |
for k in ${j}; do | |
#danger? | |
. /dev/fd/0 <<< "function ${k} () { | |
readonly action_${!j}=$k 2>/dev/null || { | |
printf 'error: use only one cmd of: %s\n' '"$j"' 1>&2; | |
return 1; | |
}; | |
}"; | |
done; | |
done; | |
# setup options | |
:; | |
# parse args | |
for a; do | |
if | |
typeset -F "$a" 1>/dev/null 2>&1; | |
then | |
"$a" && unset -f a || return 1; | |
else | |
echo unkown cmd ... 2>&1; | |
return 1; | |
fi; | |
done; | |
for i in "${!action_@}"; do | |
typeset -n j=$i; | |
printf '%s: %s\n' "${!j}" "$j"; | |
done; | |
}; | |
export \ | |
g_1='create remove' \ | |
g_2='modify'; | |
echo test 1: | |
'myscript' create modify remove; | |
echo test 2: | |
'myscript' create modify; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment