title: Bash: Ensure a command always runs when using set -euo pipefail
body: <p>I'm writing a script in Bash that looks something like this:</p>
  
  <pre><code>#!/usr/bin/env bash
  
  # Stop the script if any commands fail
  set -euo pipefail
  
  # Start a server
  yarn serve &amp;
  SERVER_PID=$!
  
  # Run some cURL requests against the server
  ...
  
  # Stop the server
  kill $SERVER_PID
  </code></pre>
  
  <p>What I'd like to do is ensure <code>kill $SERVER_PID</code> is always called at the end of the script, even if one of the server commands fails. Is there a way to accomplish this in Bash?</p>