如何查找內置bash函數的源代碼?bash內置函數bash源代碼
我知道這是一個函數:
$type -t MY_APP
function
我看到它的代碼:
type MY_APP
code
的問題是:
- 它在哪裏存儲?
- 我該如何修改它?
如何查找內置bash函數的源代碼?bash內置函數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
my_function 46 /home/dogbane/.bash/.bash_functions
# Turn off debug
shopt -u extdebug
,以編輯功能,打開包含函數定義的文件(即你從上面找到)。編輯功能並保存文件。然後,它源到你的殼,就像這樣:
$ . /path/to/function_file
功能通常存儲在.bashrc
文件(或/etc/bash.bashrc
,其中也存在一些系統,只是/etc/bashrc
)。來自SuperUser的This answer對.bashrc
文件有一些很好的細節。同樣,this question Unix上的& Linux站點詳細介紹何時最好別名,何時腳本以及何時編寫函數。
鏈接的主題很有趣。我在.bashrc和.bashprofile中搜索,定義的函數在其他地方。 @dogbane的回答幫助了我。 – idobr 2013-02-15 14:59:26
它的工作原理!我嘗試了declare -F my_function,但它僅打印沒有調試功能的函數名稱。感謝您的好建議。 – idobr 2013-02-15 14:56:35
+1我從來沒有使用'extdebug',所以不知道有一種方法可以查看函數源自的文件。非常好。 – chepner 2013-02-15 15:40:04
這太棒了! – 2013-02-15 21:24:01