5

I can define and print the contents of variable called my_var like this:

my_var="hello"
echo $my_var

but if I define:

my_funct {echo "hello";}

how can I recall my function's definition later on?

Eric Carvalho
  • 53,609
  • 102
  • 137
  • 162
Robert Vila
  • 406
  • 2
  • 10

2 Answers2

7

With the type command:

dennis@lightning:~$ foo() { echo "hi"; }
dennis@lightning:~$ type foo
foo is a function
foo () 
{ 
    echo "hi"
}
Dennis Kaarsemaker
  • 6,804
  • 25
  • 38
5

To get just the definition without "foo is a function",

$ declare -f foo
foo () 
{ 
    echo "hi"
}
glenn jackman
  • 17,625
  • 2
  • 37
  • 60