How can I create a Bash function to search for loaded functions in my environment?

0
5
Asked By CleverCat91 On

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!

2 Answers

Answered By MinimalistMaverick On

Honestly, this seems like over-engineering for what you need.

SassyScribe -

You're a towel!

Answered By QuickCoder77 On

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
```

SlyFox24 -

Another quick method is this command to list all functions:
```
set | grep '()'
```

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.