How can I create a Bash function to search for loaded functions in my environment?
Asked by
CleverCat91
I'm looking to write a Bash function that helps me quickly search for and match functions loaded in my current environment. I want it to display any functions that contain the exact text of the first argument I provide. For example, if I call `list_func 'Function: $func'`, I want it to return the entire definition of `list_func()` along with any other matching functions. I have a sample function defined, but I'm open to suggestions on optimizing it or alternative methods to achieve this. Cheers!
Answers
You can simplify things by sourcing your functions directly from your `.bashrc` file with this:
```
source ~/.bash_functions.d/*
```
Then, to list all functions, just use:
```
declare -F
```
For viewing a specific function, you can do:
```
declare -f waitForHosts
```
Reply to this answer
Honestly, this seems like over-engineering for what you need.
SassyScribe: You're a towel!
Reply to this answer
Add your answer
Answers are reviewed before publication.
SlyFox24: Another quick method is this command to list all functions: ``` set | grep '()' ```