Created
February 7, 2022 17:30
-
-
Save coderofsalvation/0cb614099c41c7025d6c2e35f4ae63a0 to your computer and use it in GitHub Desktop.
decorators / monkeypatching in bourne shell / 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
#!/bin/sh | |
# usage: | |
# ./myscript.sh foo bar | |
# handler called: foo bar | |
# i am foo | |
call(){ type on_$1 1>/dev/null 2>/dev/null && on_$1 "$@" || "$@"; } | |
on_foo(){ | |
echo before handler called: "$@" | |
"$@" | |
echo after handler called: "$@" | |
} | |
foo(){ | |
echo i am foo | |
} | |
call "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment