The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
trap command in Unix mobile01 High Level Programming 1 12-09-2006 09:43 PM
trap command mobile01 UNIX for Dummies Questions & Answers 1 11-30-2006 11:54 AM
trap command onlyc UNIX for Dummies Questions & Answers 3 07-11-2006 04:15 AM
Trap command problem superprogrammer Shell Programming and Scripting 3 06-06-2005 10:50 AM
Using TRAP command dbrundrett Shell Programming and Scripting 3 07-15-2004 10:25 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-12-2006
Deepakh Deepakh is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 4
Use of TRAP Command

Hi,

I would like to know the use of TRAP command. I am very new to the UNIX environment. I have just started learning the basic. So please teach me in a very simple way to understand.

Also i would like to know the use of following command:

trap 'dialog --msgbox "Script Aborted1" 6 50 ; error exit' 1 2 3 15..

Please let me know wat the numbers shown in the above example does mean??

Thanks in advance.


Regards
Deepakh.
  #2 (permalink)  
Old 12-12-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Quote:
Originally Posted by Deepakh
Also i would like to know the use of following command:

trap 'dialog --msgbox "Script Aborted1" 6 50 ; error exit' 1 2 3 15..

Please let me know wat the numbers shown in the above example does mean??
trap is a shell builtin which executes the command when the shell receives signals. In your example, the command would translate to 'dialog --msgbox "Script Aborted1" 6 50 ; error exit'. The signals translates to 1, 2, 3 and 15.

Hence whenever your script receives any of the signal 1, 2, 3 or 15, then a popup comes up with the message "Script Aborted1" and the script exits.

From man 7 signal, this is what the numbers stand for
Code:
       Signal     Value     Action   Comment
       -------------------------------------------------------------------------
       SIGHUP        1       Term    Hangup detected on controlling terminal
                                     or death of controlling process
       SIGINT        2       Term    Interrupt from keyboard
       SIGQUIT       3       Core    Quit from keyboard
       SIGILL        4       Core    Illegal Instruction
       SIGABRT       6       Core    Abort signal from abort(3)
       SIGFPE        8       Core    Floating point exception
       SIGKILL       9       Term    Kill signal
       SIGSEGV      11       Core    Invalid memory reference
       SIGPIPE      13       Term    Broken pipe: write to pipe with no readers
       SIGALRM      14       Term    Timer signal from alarm(2)
       SIGTERM      15       Term    Termination signal
       SIGUSR1   30,10,16    Term    User-defined signal 1
       SIGUSR2   31,12,17    Term    User-defined signal 2
       SIGCHLD   20,17,18    Ign     Child stopped or terminated
       SIGCONT   19,18,25            Continue if stopped
       SIGSTOP   17,19,23    Stop    Stop process
       SIGTSTP   18,20,24    Stop    Stop typed at tty
       SIGTTIN   21,21,26    Stop    tty input for background process
       SIGTTOU   22,22,27    Stop    tty output for background process
The signals SIGKILL and SIGSTOP can not be trapped.
  #3 (permalink)  
Old 12-12-2006
Deepakh Deepakh is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 4
Thumbs up hi

Thanks Vino.

That was really useful.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:20 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0