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 9238399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:45:11+00:00 2026-06-18T07:45:11+00:00

I want to fire a command like rm -rf /etc/XXX.pid when the shell script

  • 0

I want to fire a command like ” rm -rf /etc/XXX.pid” when the shell script is interrupted in the middle of its execution. Like using CTRL+C
Can anyone help me what to do here?

  • 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-18T07:45:12+00:00Added an answer on June 18, 2026 at 7:45 am

    Although it may come as a shock to many, you can use the bash built-in trap to trap signals 🙂

    Well, at least those that can be trapped, but CTRL-C is usually tied to the INT signal (it can be changed with stty but let’s discount that possibility for simplicity).

    You can therefore trap the signals and execute arbitrary code. For example, the following script will ask you to enter some text then echo it back to you. If perchance, you generate an INT signal, it simply growls at you and exits:

    #!/bin/bash
    
    exitfn () {
      trap SIGINT            # Restore signal handling for SIGINT.
      echo; echo 'Aarghh!!'  # Growl at user,
      exit                   #   then exit script.
    }
    
    trap "exitfn" INT        # Set SIGINT trap to call function.
    
    read -p "What? "         # Ask user for input,
    echo "You said: $REPLY"  #   then echo back.
    
    trap SIGINT              # Restore signal handling.
    

    A test run transcript follows (a fully entered line, a line with pressing CTRL-C before any entry, and a line with partial entry before pressing CTRL-C):

    pax> ./testprog.sh 
    What? hello there
    You said: hello there
    
    pax> ./testprog.sh 
    What? ^C
    Aarghh!!
    
    pax> ./qq.sh
    What? incomplete line being entere... ^C
    Aarghh!!
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write one shell script like command1 ssh vivek@remotehost fire command on
i want to fire an event manually using c#. For instance, say if i
I just want to fire an event when an input changes value using jQuery
I want to fire a command line executible with the parameters entered in GUI.
I want to fire an update query , normally using groovy we do something
I want to fire an event after loading all images. And also, I want
Onsubmit I want to fire fancybox popup I need only to show the fancybox
After a user cancels a delete confirmation I want to fire a javascript call
I have a periodically_call_remote that I want to fire right away (as if the
I have several sql queries that I simply want to fire at the database.

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.