title: Catch SIGINT in bash, handle AND ignore
body: <p>Is it possible in bash to intercept a SIGINT, do something, and then ignore it (keep bash running).</p>
  
  <p>I know that I can ignore the SIGINT with</p>
  
  <pre><code>trap '' SIGINT
  </code></pre>
  
  <p>And I can also do something on the sigint with</p>
  
  <pre><code>trap handler SIGINT
  </code></pre>
  
  <p>But that will still stop the script after the <code>handler</code> executes. E.g.</p>
  
  <pre><code>#!/bin/bash
  
  handler()
  {
      kill -s SIGINT $PID
  }
  
  program &amp;
  PID=$!
  
  trap handler SIGINT
  
  wait $PID
  
  #do some other cleanup with results from program
  </code></pre>
  
  <p>When I press ctrl+c, the SIGINT to program will be sent, but bash will skip the <code>wait</code> BEFORE program was properly shut down and created its output in its signal handler.</p>
  
  <p>Using @suspectus answer I can change the <code>wait $PID</code> to:</p>
  
  <pre><code>while kill -0 $PID &gt; /dev/null 2&gt;&amp;1
  do
      wait $PID
  done
  </code></pre>
  
  <p>This actually works for me I am just not 100% sure if this is 'clean' or a 'dirty workaround'.</p>