Can anybody help me to use trap in sh?
A simple script is:
---------
#!/bin/sh
trap "echo trapped" 1 2 15
trap "echo ok" 0
exit 1
echo continue
---------
The result is
ok
I expect
trapped
What's wrong?
Thank you.
I expect
trapped
What's wrong?
Thank you.
> Can anybody help me to use trap in sh?
> A simple script is:
> ---------
> #!/bin/sh
> trap "echo trapped" 1 2 15
> trap "echo ok" 0
> exit 1
> echo continue
> ---------
> The result is
> ok
> I expect
> trapped
> What's wrong?
> Thank you.
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Ph: 018-978656
------------------------------------------------------------------------
Lobbying the government to increase the height on Mt Kosiuskco by
another 1000 metres so that it will have a permanent snow cover.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
When exiting a script a signal number 0 is generated which is what
causes the unexpected response.
To test the trap code, one needs to place the script in a perpetual
loop in the background and then send signals with kill and quit
keyboard sequences.
Remember that triggering the trap code will not cause automatic
termination of the script. The trap code should end with an exit
(after disabling the trap 0 if set)
1. Execute a sh script under perl and sh: sh script; perl script?
I can execute the following perl scripts under either shell or Perl
====
if 0;
[perl scripts ...]
====
i.e.
sh script
perl script
How do I execute a sh script under either shell or Perl
simililar to what shown above?
Thanks.
--
Michael Wang
http://www.mindspring.com/~mwang
2. Raw Informix 723uc3 db backup
3. strange traps in HP-UX /bin/sh
4. sed question
5. signal trapping problem in [k]sh...
6. scsi logging
8. NetBSD-1.1 (i386) and hard disk..
10. Error trap/detection question in sh
11. How secure is trap sh on UNIX generally, AIX in particular?
12. How to clean up when killed (trap in sh)?
13. Can someone explain the 'trap' command in /bin/sh?