title: Programmatically dereference/resolve aliases in bash
body: <p>I need to determine which command a shell alias resolves to in bash, programmatically; i.e., I need to write a bash function that will take a name potentially referring to an alias and return the "real" command it ultimately refers to, <strong>recursing through chains of aliases where applicable.</strong></p>
  
  <p>For example, given the following aliases:</p>
  
  <pre><code>alias dir='list -l'
  alias list='ls'
  </code></pre>
  
  <p>where my function is <code>dereference_alias</code>,</p>
  
  <pre><code>dereference_alias list    # returns "ls"
  dereference_alias dir     # also returns "ls"
  </code></pre>
  
  <p>Is there some builtin I don't know about that does this neatly, or shall I resign myself to scraping the output of <code>alias</code>?</p>