In Bash, you can list functions loaded in your current environment—including those loaded via the source (or .) command—using several built-in methods.
1. List All Loaded Functions
To see every function currently defined in your shell environment:
- List names only:
declare -F - List names and definitions:
declare -f - Using
typeset:typeset -f(performs the same action asdeclare -f)
2. Identify Source File and Line Numbers
If you need to know exactly where a function was sourced from, you must enable the extdebug shell option before running the list command:
- Enable extended debugging:
shopt -s extdebug - Display location:
declare -F <function_name>- Note: When
extdebugis on,declare -Ffollowed by a function name will output the name, line number, and the source file path.
- Note: When
- Disable when finished:
shopt -u extdebug
3. List Functions from a Specific Script
If you want to see which functions will be loaded by sourcing a specific file without permanently loading them into your current shell, use a subshell:
# Sourcing the file in a subshell and dumping the resulting functions
bash -c ". ./your_script.sh; declare -F"
4. Summary Table of Commands
| Goal | Command |
|---|---|
| List all function names | declare -F |
| List names & code | declare -f |
| See source file/line | shopt -s extdebug; declare -F [name] |
| Filter just the names | `declare -F |
For more advanced shell management, you can refer to the official Bash Reference Manual.
bash -c ". ./docker-prune-review.sh; declare -F"
declare -f collect_container_data
declare -f generate_action_plan
declare -f generate_report
declare -f logic
declare -f main
declare -f parse_cmd_line
declare -f usage
declare -f validate_arguments
bash -c ". ./devops-bash-lib.sh; declare -F"
declare -f align
declare -f convert_to_bytes
declare -f date_dif
declare -f debug_end_timer
declare -f debug_start_timer
declare -f generate_removal_snippet
declare -f get_docker_bulk_metadata
declare -f get_docker_container_diff
declare -f get_docker_container_image
declare -f get_docker_container_mounts
declare -f get_docker_container_name
declare -f get_docker_container_size_info
declare -f get_docker_container_vols_list
declare -f get_docker_containers_by_status
declare -f get_docker_system_df
declare -f get_dttm
declare -f header
declare -f msg_help_section
declare -f progress_bar
