Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What does set -T mean in bash? What does it do? I believe it is related to traps in Unix but I am not sure.

I found this:

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

{     trap SIGINT     kill -SIGINT $$
set -T            # set async execution of traps on FreeBSD
trap onsig SIGINT
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.

share|improve this question

migrated from Aug 7 '11 at 1:23

This question came from our site for professional and enthusiast programmers.

Maybe this question will be of interest for you:… (about errtrace) – hmontoliu Aug 7 '11 at 7:28
up vote 6 down vote accepted

From help set:

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

So if you use trap to invoke a function on DEBUG (that is, almost before every command in a shell script) and then invoke another shell script, the trapping will occur in that script as well. Without this option, the trap will not exist in the subshell and the script invoked in it will run untrapped.

share|improve this answer
Thanks. Thats what I also found while googling. – hari Aug 7 '11 at 1:31

this is what man bash says (hint: it's a huge file, I usually search for ..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.
share|improve this answer
Thanks much for the pointer. – hari Aug 7 '11 at 1:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.