simple trap syntax
am 30.12.2007 23:16:09 von Harry Putnam
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", , ...
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?
Re: simple trap syntax
am 30.12.2007 23:44:46 von Cyrus Kriticos
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?docid=-7960687976401601534
Re: simple trap syntax
am 30.12.2007 23:51:26 von Harry Putnam
Cyrus Kriticos 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.
Re: simple trap syntax
am 31.12.2007 00:15:33 von Icarus Sparry
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", , ...
>
> 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.
Re: simple trap syntax
am 31.12.2007 01:32:45 von wayne
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", , ...
>
> 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
Re: simple trap syntax
am 03.01.2008 09:37:14 von Harry Putnam
Icarus Sparry writes:
> On Sun, 30 Dec 2007 16:16:09 -0600, reader wrote:
[...]
>>
>> "trap -- %s %s ...\n", , ...
>>
>> 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", , ...
>
> Simple example.
>
> bash -c 'trap "echo BING" 2 ; trap ; sleep 10'
>
Nice... I think I get it now. Thanks
Re: simple trap syntax
am 03.01.2008 09:40:31 von Harry Putnam
Wayne 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.