title: How to trap ERR when using 'set -e' in Bash
body: <p>I have a simple script : </p>
  
  <pre><code>#!/bin/bash
  set -e
  trap "echo BOO!" ERR 
  
  function func(){
      ls /root/
  }
  
  func
  </code></pre>
  
  <p>I would like to trap ERR if my script fails (as it will here b/c I do not have the permissions to look into /root). However, when using <code>set -e</code> it is not trapped. Without <code>set -e</code> ERR is trapped.  </p>
  
  <p>According to the bash man page, for <code>set -e</code> : </p>
  
  <blockquote>
    <p>... A trap on ERR, if set, is executed before the  shell  exits. ...</p>
  </blockquote>
  
  <p>Why isn't my trap executed?  From the man page it seems like it should.</p>