Do you want BuboFlash to help you learning these things? Or do you want to add or correct something? Click here to log in or create user.



Question

In linux, complete the following shell script snippet, to ensure on_exit function is run whenever the SIGINT signal is sent (i.e. when user presses ctr-c):

#!/bin/sh
 
function on_exit ()
{
    echo 'Bye bye'
}
 
[...]
 
sleep 500

Answer

trap on_exit SIGINT

^^ note the use of trap built-in command to bind the signal SIGINT to function on_exit

^^^ note the order of command line arguments given to trap, i.e. the binding functon is given first, then the signal


Question

In linux, complete the following shell script snippet, to ensure on_exit function is run whenever the SIGINT signal is sent (i.e. when user presses ctr-c):

#!/bin/sh
 
function on_exit ()
{
    echo 'Bye bye'
}
 
[...]
 
sleep 500

Answer
?

Question

In linux, complete the following shell script snippet, to ensure on_exit function is run whenever the SIGINT signal is sent (i.e. when user presses ctr-c):

#!/bin/sh
 
function on_exit ()
{
    echo 'Bye bye'
}
 
[...]
 
sleep 500

Answer

trap on_exit SIGINT

^^ note the use of trap built-in command to bind the signal SIGINT to function on_exit

^^^ note the order of command line arguments given to trap, i.e. the binding functon is given first, then the signal

If you want to change selection, open document below and click on "Move attachment"

20. Advanced Shell Scripting
recieved' } trap on_hangup SIGHUP while true ; do sleep 1 done exit 0 Run the above script and then send the process ID the -HUP signal to test it. (See Section 9.5.) An important function of a <span>program is to clean up after itself on exit. The special signal EXIT (not really a signal) executes code on exit of the script: 5 10 #!/bin/sh function on_exit () { echo 'I should remove temp files now' } trap on_exit EXIT while

Summary

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

Details

No repetitions


Discussion

Do you want to join discussion? Click here to log in or create user.