Bash inline function bash source code

How to find the source of a bash built-in function?

I know this is a function:

$type -t MY_APP function 

I see the code:

 type MY_APP code 

Questions:

  • Where is it stored?
  • How can I change it?
+6
source share
2 answers

You can do it as follows:

 # Turn on debug $ shopt -s extdebug # Print out the function 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 a function, open the file containing the function definition (which you found above). Edit the function and save the file. Then enter it into your shell, for example:

 $ . /path/to/function_file 
+7
source

Functions are usually stored in a .bashrc (or in /etc/bash.bashrc , which also exists as /etc/bashrc on some systems). This answer from SuperUser contains good information on what a .bashrc file is. Similarly, this question is on the details of the Unix and Linux site, when is it best suited for an alias, when is a script and when to write a function.

0
source

All Articles