title: Suppress output when killing parent
body: <p>How can you suppress the the output resulting from <code>kill</code> when the target process is a parent of the current one?</p>
  
  <p>I'm using the following function to exit out of any level of nested shells but keep the last one open:</p>
  
  <pre><code>function surface(){
      if [ $SHLVL -gt 1 ]; then
          target=$(pstree -p $$ | grep -m 2 sh$ | tail -1 | awk '{print $2}') &amp;&gt;/dev/null
          kill -1 $target &amp;&gt;/dev/null
      fi
  }
  </code></pre>
  
  <p>But this still prints the message <code>Hangup: 1</code> to the terminal. </p>
  
  <p>Adding <code>wait $target</code> after <code>kill</code> fails, as <code>wait</code> gives the error: <code>bash: wait: pid 1234 is not a child of this shell</code>.</p>
  
  <p>I also tried using <code>disown</code>, but that similarly fails because the target process is a parent of the current one.</p>
  
  <p>Related: </p>
  
  <p><a href="https://stackoverflow.com/questions/81520/how-to-suppress-terminated-message-after-killing-in-bash">How to suppress Terminated message after killing in bash?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/8074904/how-to-shield-the-kill-output">How to shield the kill output</a></p>
  
  <p><a href="https://stackoverflow.com/questions/5719030/bash-silently-kill-background-function-process/5722850">bash: silently kill background function process</a></p>