How to find source of a built in bash function?
I know that it is a function:
$type -t MY_APP
function
I see it's code:
type MY_APP
code
The questions are:
About source. source is a builtin command of the Bash shell. It takes a file name, and executes the commands in that file as if they had been typed on the command line. Using source to execute the commands in a file is not the same as running a script.
In Bash, defining a function is as easy as setting it either in the script file you're writing or in a separate file. If you save functions to a dedicated file, you can source it into your script as you would include a library in C or C++ or import a module into Python.
You can make modifications in configuration files, such as ~/.bashrc and ~/.profile, you can run services at startup, and you can create your own custom commands or script your own Bash functions. Bash (along with some other shells) has a built-in command called source.
Think of bash functions as small snippets of code that save you time and space by eliminating the need to constantly type or copy the same sets of commands. However, the capabilities of the functions are much wider. In particular, we are talking about passing arguments to them.
You can do it like this:
# Turn on debug
$ shopt -s extdebug
# Print out the function's name, line number and file where it was sourced from
$ declare -F my_function
my_function 46 /home/dogbane/.bash/.bash_functions
# Turn off debug
shopt -u extdebug
To edit the function, open the file containing the function definition (that you found from above). Edit the function and save the file. Then source it into your shell, like this:
$ . /path/to/function_file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With