PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > simple trap syntax
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

simple trap syntax

Réponse
 
LinkBack Outils de la discussion
Vieux 30/12/2007, 22h16   #1
reader@newsguy.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut simple trap syntax

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?

  Réponse avec citation
Vieux 30/12/2007, 22h44   #2
Cyrus Kriticos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: simple trap syntax

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
  Réponse avec citation
Vieux 30/12/2007, 22h51   #3
reader@newsguy.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: simple trap syntax

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.
  Réponse avec citation
Vieux 30/12/2007, 23h15   #4
Icarus Sparry
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: simple trap syntax

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.
  Réponse avec citation
Vieux 31/12/2007, 00h32   #5
Wayne
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: simple trap syntax

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
  Réponse avec citation
Vieux 03/01/2008, 08h37   #6
reader@newsguy.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: simple trap syntax

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
  Réponse avec citation
Vieux 03/01/2008, 08h40   #7
reader@newsguy.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: simple trap syntax

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.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 14h10.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,15519 seconds with 15 queries