[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Q: bash: trap in subshell
From: |
Chet Ramey |
Subject: |
Re: Q: bash: trap in subshell |
Date: |
Fri, 25 Apr 2008 14:56:35 -0400 |
User-agent: |
Thunderbird 2.0.0.12 (Macintosh/20080213) |
Dmitry V. Levin wrote:
Hi,
I wonder whether such difference in "trap" behavior is valid:
$ sh -c 'f() { echo f; }; t() { trap f EXIT; trap; }; t'
trap -- 'f' EXIT
f
$ sh -c 'f() { echo f; }; t() { trap f EXIT; trap; }; t&'
trap -- 'f' EXIT
$ sh -c 'f() { echo f; }; t() { trap f EXIT; trap; }; (t)&'
trap -- 'f' EXIT
f
Bash does not run the exit trap in a process forked to run an
asynchronous simple command, regardless of whether or not that
command is a shell function or builtin. It makes special provisions
to run the exit trap in a user-specified subshell -- () -- even
when that subshell is run asynchronously.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
Live Strong. No day but today.
Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/