title: How to re-prompt after a trap return in bash?
body: <p>I have a script that is supposed to trap SIGTERM and SIGTSTP. This is what I have in the main block:</p>
  
  <pre><code>trap 'killHandling' TERM
  </code></pre>
  
  <p>And in the function:</p>
  
  <pre><code>killHandling () {
      echo received kill signal, ignoring
      return
  }
  </code></pre>
  
  <p>... and similar for SIGINT. The problem is one of user interface. The script prompts the user for some input, and if the SIGTERM or SIGINT occurs when the script is waiting for input, it's confusing. Here is the output in that case:</p>
  
  <pre><code>Enter something:     # SIGTERM received
  received kill signal, ignoring
  
        # shell waits at blank line for user input, user gets confused
        # user hits "return", which then gets read as blank input from the user
        # bad things happen because of the blank input
  </code></pre>
  
  <p>I have definitely seen scripts which handle this more elegantly, like so:</p>
  
  <pre><code>Enter something:     # SIGTERM received
  received kill signal, ignoring
  Enter something:     # re-prompts user for user input, user is not confused
  </code></pre>
  
  <p>What is the mechanism used to accomplish the latter? Unfortunately I can't simply change my trap code to do the re-prompt as the script prompts the user for several things and what the prompt says is context-dependent. And there has to be a better way than writing context-dependent trap functions. </p>
  
  <p>I'd be very grateful for any pointers. Thanks!</p>