Linux bash内置函数bash源代码
如何找到内置bash函数的源代码 我知道这是一个函数:Linux bash内置函数bash源代码,linux,bash,shell,built-in,Linux,Bash,Shell,Built In,如何找到内置bash函数的源代码 我知道这是一个函数: $type -t MY_APP function 我看到它的代码: type MY_APP code 问题是: 它存放在哪里 如何修改它 您可以这样做: # 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 m
$type -t MY_APP
function
我看到它的代码:
type MY_APP
code
问题是:
您可以这样做:
# 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
$ . /path/to/function_file
要编辑函数,请打开包含函数定义的文件(从上面找到)。编辑函数并保存文件。然后将其源代码放入shell中,如下所示:
# 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
$ . /path/to/function_file
函数通常存储在
.bashrc
文件中(或者存储在/etc/bash.bashrc
中,在某些系统上,它也作为/etc/bashrc
存在)。“超级用户”提供了一些关于.bashrc
文件的详细信息。类似地,在Unix&Linux站点上详细介绍了何时最好使用别名、何时编写脚本以及何时编写函数。它可以工作!我尝试声明-F my_函数,但它只打印函数名,而不打印调试函数。感谢您的建议。+1我从未使用过extdebug
,因此不知道有什么方法可以查看函数的源文件。很好。链接的主题很有趣。我在.bashrc和.bashprofile中搜索,定义的函数位于其他位置。“罗布麻”的答案帮助了我。