Created
September 24, 2021 18:54
-
-
Save squeedee/ba7dc61758ebf9185bc23fc35823c4c3 to your computer and use it in GitHub Desktop.
Code as a script but with re-entrant/debug access to functions
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
#!/usr/bin/env bash | |
# usages: | |
# As a script: | |
# $ ./can_debug.bash | |
# > you are Rasheed Abdul-Aziz | |
# As a library of functions: | |
# $ source can_debug.bash | |
# $ say_my_name | |
# > usage: say_my_name <your-name-here> | |
# $ say_my_name "Ted Lasso" | |
# > you are Ted Lasso | |
main() { | |
[[ ! -z $DEBUG ]] && set -x | |
say_my_name "Rasheed Abdul-Aziz" | |
} | |
say_my_name() { | |
name="$1" | |
if [[ -z $name ]]; then | |
echo "usage: say_my_name <your-name-here>" | |
return 1 | |
fi | |
echo "you are $name" | |
} | |
[[ "${BASH_SOURCE[0]}" == "${0}" ]] && main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment