你如何在 bash 中打印/调用函数的定义

Rob*_*ila 5 bash functions environment-variables

我可以像这样定义和打印名为 my_var 的变量的内容:

my_var="hello"
echo $my_var
Run Code Online (Sandbox Code Playgroud)

但如果我定义:

my_funct {echo "hello";}
Run Code Online (Sandbox Code Playgroud)

我以后如何回忆我的函数定义?

Den*_*ker 6

使用type命令:

dennis@lightning:~$ foo() { echo "hi"; }
dennis@lightning:~$ type foo
foo is a function
foo () 
{ 
    echo "hi"
}
Run Code Online (Sandbox Code Playgroud)


gle*_*man 5

为了得到没有“foo是一个函数”的定义,

$ declare -f foo
foo () 
{ 
    echo "hi"
}
Run Code Online (Sandbox Code Playgroud)