set -T no bash - o que isso faz?

1

O que significa set -T no bash? O que isso faz? Acredito que esteja relacionado a armadilhas no Unix, mas não tenho certeza.

Eu encontrei este :

Many of such constructs become more simple if traps would be called immedeately, while is foreground child is still running. You would just install a trap handler that does "something" about the problem and it would be called everytime you hit SIGINT (or SIGQUIT). Just as signals handler in C programs are called immedeately. Maybe I am too much of a C programmer, but I find the delayed sh behaviour very non-intuitive.

#! /bin/sh

onsig()
{     trap SIGINT     kill -SIGINT $$
}
set -T            # set async execution of traps on FreeBSD
trap onsig SIGINT
./some-blocking-program
set +T            # set traps execution behaviour back to normal

This makes the trap handler a bit more complicated, but it allows you to write the main part of your shell script as usualy, without keeping in mind that a program may block and taking the appropriate action about it.

    
por hari 07.08.2011 / 03:20

2 respostas

8

De help set :

  -T  If set, the DEBUG trap is inherited by shell functions.

Portanto, se você usar trap para invocar uma função em DEBUG (ou seja, quase antes de cada comando em um script de shell) e invocar outro script de shell, o trapping também ocorrerá nesse script. Sem essa opção, a armadilha não existirá na subshell e o script invocado nela será executado sem armadilhas.

    
por 07.08.2011 / 03:24
2

é isso que o man bash diz (dica: é um arquivo enorme, eu normalmente pesquiso por ..lotsofspaces..set )

If  set,  any  traps  on  DEBUG and RETURN are inherited by
shell functions, command substitutions, and  commands  exe-
cuted  in  a  subshell  environment.   The DEBUG and RETURN
traps are normally not inherited in such cases.
    
por 07.08.2011 / 03:26

Tags