title: Get a list of function names in a shell script
body: <p>I have a Bourne Shell script that has several functions in it, and allows to be called in the following way:</p>
  
  <pre><code>my.sh &lt;func_name&gt; &lt;param1&gt; &lt;param2&gt;
  </code></pre>
  
  <p>Inside, <code>func_name()</code> will be called with <code>param1</code> and <code>param2</code>.</p>
  
  <p>I want to create a <code>help</code> function that would just list all available functions, even without parameters. </p>
  
  <p>The question: how do I get a list of all function names in a script from inside the script?</p>
  
  <p>I'd like to avoid having to parse it and look for function patterns. Too easy to get wrong.</p>
  
  <p>Update: the code. Wanted my <code>help()</code> function be like <code>main()</code> - a function added to the code is added to the help automatically.</p>
  
  <pre><code>#!/bin/sh
  
  # must work with "set -e"
  
  foo ()
  {
      echo foo: -$1-$2-$3-
      return 0
  }
  
  # only runs if there are parameters
  # exits
  main ()
  {
      local cmd="$1"
      shift
      local rc=0
      $cmd "$@" || rc=$?
      exit $rc
  }
  
  if [[ "$*" ]]
  then
      main "$@"
      die "how did we get here?"
  fi
  </code></pre>