Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8406745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:11:42+00:00 2026-06-09T23:11:42+00:00

I have a script that is supposed to trap SIGTERM and SIGTSTP. This is

  • 0

I have a script that is supposed to trap SIGTERM and SIGTSTP. This is what I have in the main block:

trap 'killHandling' TERM

And in the function:

killHandling () {
    echo received kill signal, ignoring
    return
}

… 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:

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

I have definitely seen scripts which handle this more elegantly, like so:

Enter something:     # SIGTERM received
received kill signal, ignoring
Enter something:     # re-prompts user for user input, user is not confused

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.

I’d be very grateful for any pointers. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:11:43+00:00Added an answer on June 9, 2026 at 11:11 pm

    The answer CodeGnome gave works, but as he points out, it is not robust; a second control-c causes undesirable behavior. I ultimately got around the problem by making better use of existing input validation in the code. So my interrupt handling code now looks like this:

    killHandling () {
       echo received kill signal, ignoring
       echo "<<Enter>> to continue"
       return
    }
    

    Now the cursor still waits at a blank line for user input, but the user is not confused, and hits the “Enter” key as prompted. Then the script’s input validation detects that a blank line has been entered, which is treated as invalid input, and the user is re-prompted to enter something.

    I remain grateful to CodeGnome for his suggestions, from which I learned a couple of things. And I apologize for the delay in posting this answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function in a powershell script that is supposed to untar my
I have a Perl script, that's supposed to match this string: Sometimes, he says
I have a function in my script that's supposed to take in a string
I have a script that is supposed to sit there, happily running in a
I have a PHP script that's supposed to take in a URL and search
I have a Ruby 1.8.6 script that is supposed to take a filename that
I have this script that run to fix my menu bar to the browser
I'm trying to design this script that's supposed to be used as a part
I have a script that is supposed to read from the database and return
I have a script task in an SSIS package that is supposed to retrieve

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.