Trap --- I am confused .......
1 Attachment(s)
I am trying to understand how traps work so I can expand my knowledege. From what I read if the signals listed are recieved from a source outside the script then the command is run upon recieving the signal.
I have tried a few modifications of this but no dice. :doh: However the function does get placed in the environment of the shell so if I type fx I get the result. I have included a screenshot of what I get upon CTRL Z / C and the script I have been trying to learn through. Any direction would be appreciated. :hattip: Code:
#! /bin/bash |
The trap command is used for two purposes:
Code:
trap [ arg ] [ sig ] These trap conditions are valid:
Code:
# Exit on signal 2 Code:
Signal Name Meaning Code:
Command Purpose Example Hope this helps some. |
What exactly are you confused about? It's not completely clear to me from your post or your screenshot.
I'm not really an expert on it, but if you're asking about how to trap the ctrl+z (SIGTSTP) signal, I believe your problem is mostly that the job control of the running shell is catching it before it gets to the script. When I use set +m to disable job control, I can trap that signal with no problem. In any case the usual purpose of trap in a script is simply to run some kind of cleanup function if it should terminate irregularly. So I think SIGHUP, SIGINT and SIGTERM are usually the ones you mostly need to be worried about. You can also include the EXIT pseudo-signal to also execute it when the script exits. Code:
trapit(){ |
Thank you all for the inisght and direction. It was a great help. My hang up in this test script was the placement as David the H. suggested.
:study: --> Back to studying ---> :) Code:
#! /bin/bash |
All times are GMT -5. The time now is 09:03 PM. |