idobr
idobr

Reputation: 1647

bash built in function bash source code

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:

  1. Where is it stored?
  2. How can I modify it?

Upvotes: 6

Views: 1326

Answers (2)

Jonah Bishop
Jonah Bishop

Reputation: 12581

Functions are typically stored in the .bashrc file (or in /etc/bash.bashrc, which also exists as just /etc/bashrc on some systems). This answer from SuperUser has some good details on what a .bashrc file is. Similarly, this question on the Unix & Linux site details when it's best to alias, when to script, and when to write a function.

Upvotes: 0

dogbane
dogbane

Reputation: 274622

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

Upvotes: 7

Related Questions