Skip to content

Instantly share code, notes, and snippets.

@squeedee
Created September 24, 2021 18:54
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 squeedee/ba7dc61758ebf9185bc23fc35823c4c3 to your computer and use it in GitHub Desktop.
Save squeedee/ba7dc61758ebf9185bc23fc35823c4c3 to your computer and use it in GitHub Desktop.
Code as a script but with re-entrant/debug access to functions
#!/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