|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Anyone have some simple examples of using trap? I find the man page
really confusing. This piece: [...] The trap command with no arguments shall write to standard output a list of commands associated with each condition. The format shall be: "trap -- %s %s ...\n", <action>, <condition> ... How is this used... all I get is one or another error indicating my syntax sucks. Can this be run a cmd prompt and be made to return anything but errors? |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
reader@newsguy.com wrote:
> Anyone have some simple examples of using trap? I find the man page > really confusing. Some examples from Advanced Bash-Scripting Guide: http://www.tldp.org/LDP/abs/html/debugging.html#EX76 -- Best regards Cyrus From a jewish slaughterhouse in Iowa (undercover) http://video.google.com/videoplay?do...87976401601534 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Cyrus Kriticos <cyrus.kriticos@googlemail.com> writes:
> reader@newsguy.com wrote: >> Anyone have some simple examples of using trap? I find the man page >> really confusing. > > Some examples from Advanced Bash-Scripting Guide: > http://www.tldp.org/LDP/abs/html/debugging.html#EX76 Man that is really nice... just exactly what I needed. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Sun, 30 Dec 2007 16:16:09 -0600, reader wrote:
> Anyone have some simple examples of using trap? I find the man page > really confusing. > > This piece: > [...] > The trap command with no arguments shall write to standard > output a list of commands associated with each condition. The > format shall be: > > > "trap -- %s %s ...\n", <action>, <condition> ... > > How is this used... all I get is one or another error indicating my > syntax sucks. > > Can this be run a cmd prompt and be made to return anything but errors? Which manual did this come from? Simple example. bash -c 'trap "echo BING" 2 ; trap ; sleep 10' then whist this is running type your tty interrupt character (usually Control-C). This runs a 3 command shell script. The first command sets up a trap handler for the interrupt character. The second command lists the currently set traps. The third runs a command that waits for a bit. When you type the Control-C it exits the sleep program and triggers the trap. |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
reader@newsguy.com wrote:
> Anyone have some simple examples of using trap? I find the man page > really confusing. > > This piece: > [...] > The trap command with no arguments shall write to standard output a > list of commands associated with each condition. The format shall be: > > > "trap -- %s %s ...\n", <action>, <condition> ... > > How is this used... all I get is one or another error indicating my > syntax sucks. > > Can this be run a cmd prompt and be made to return anything but > errors? > You can change the action of the shell when it receives a signal using the trap command: trap 'command' sig_list For example: trap 'rm $TMP; trap - 0; exit 0' 0 1 2 3 15 If command is a single "-" then reset to default action for listed signals (some shells also do that if command is missing completely). If command is null than the shell will ignore the listed signals. Using trap without any arguments (or just --) produces a list of the modified traps set, in a way that can be reused. For some simple but practical examples, try (my) web page at: http://www.hccfl.edu/pollock/ShScript/TempFile.htm#trap -Wayne |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
Icarus Sparry <usenet@icarus.freeuk.com> writes:
> On Sun, 30 Dec 2007 16:16:09 -0600, reader wrote: [...] >> >> "trap -- %s %s ...\n", <action>, <condition> ... >> >> How is this used... all I get is one or another error indicating my >> syntax sucks. >> >> Can this be run a cmd prompt and be made to return anything but errors? > > Which manual did this come from? TRAP(1P) POSIX Programmer's Manual TRAP(1P) PROLOG This manual page is part of the POSIX Programmer's Manual. The Linux [...] Under the description part: [...] The trap command with no arguments shall write to standard output a list of commands associated with each condition. The format shall be: "trap -- %s %s ...\n", <action>, <condition> ... > > Simple example. > > bash -c 'trap "echo BING" 2 ; trap ; sleep 10' > Nice... I think I get it now. Thanks |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
Wayne <nospam@all4me.invalid> writes:
> For some simple but practical examples, try (my) web page at: > > http://www.hccfl.edu/pollock/ShScript/TempFile.htm#trap Thanks for little example and the very nice link. Good material there. I love real examples like that... I think its against the law to put examples in unix man pages though... hehe... There is certainly a dirth of them there. |
|
![]() |
| Outils de la discussion | |
|
|