title: Portably trapping ERR in shell script
body: <p>I'm trying to write a shell script that aborts when a command fails and displays the offending line number.</p>
  
  <pre><code>set -e
  trap 'echo "$0 FAILED at line ${LINENO}"' ERR
  </code></pre>
  
  <p>Turned out the trap line does not work with Ubuntu's default shell script interpreter, dash. If I change the shebang line to <code>#!/bin/bash</code> this works but not with <code>#!/bin/sh</code>. Is there a way to make this work without relying on bash being present?</p>
  
  <p>By the way, The error I get from dash is this:</p>
  
  <pre><code>trap: ERR: bad trap
  </code></pre>