Thursday, March 27, 2008

Handling of signals in Shell scripting..

trap [-lp] [arg] [sigspec ...]

The command arg is to be read and executed when the shell receives signal(s) sigspec। If arg is absent or -, all specified signals are reset to their original values (the values they had upon entrance to the shell)।
If arg is the null string the signal specified by each sigspec is ignored by the shell and by the commands it invokes।
If arg is not present and -p has been supplied, then the trap commands associated with each sigspec are displayed।
If no arguments are supplied or if only -p is given, trap prints the list of commands associated with each signal number।
Each sigspec is either a signal name defined in <signal.h>, or a signal number।
If a sigspec is EXIT (0) the command arg is executed on exit from the shell। If a
sigspec is DEBUG, the command arg is executed after every simple command (see SHELL GRAMMAR above)।
If a sigspec is ERR, the command arg is executed whenever a simple command has a non-zero exit status।
The ERR trap is not executed if the failed command is part of an until or while loop, part of an if statement, part of a && or || list, or if the command's return value is being inverted via !. The -l option causes the shell to print a list of signal names and their corresponding numbers। Signals ignored upon entry to the shell cannot be trapped or reset। Trapped signals are reset to their original values in a child process when it is created। The return status is false if any sigspec is invalid; otherwise trap returns true.

No comments: