Command to be run when it is terminated by Ctrl+C

Is there a reserved command name that will be run when the entire script is terminated by the user with Control+c? For example, if I wanted to do puts "Script terminated by user." when the script is terminated, how can I do it?

Answers


trap("INT") do
  puts "Script terminated by user."
  exit
end

sleep 10

Run this, and hit ctrl-c.


Need Your Help

jQuery toggle class on child element

javascript jquery css

I have list of links, and if you click on any of them, it will toggle show/hide text below it in separate div. Also it hides all other divs if one of them is shown

adding onsubmit to drupal login forms

drupal drupal-6

the default login form in drupal doesn't have any javascript to check whether the fields(Username and password) are empty or not before submitting the form.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.