Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site sdcrdcf.UUCP Path: utzoo!decvax!decwrl!pyramid!nsc!hplabs!sdcrdcf!curt From: curt@sdcrdcf.UUCP (Curt Dodds) Newsgroups: net.unix Subject: Re: Can a trap survive an exec /bin/sh? Message-ID: <2367@sdcrdcf.UUCP> Date: Fri, 27-Sep-85 19:06:31 EDT Article-I.D.: sdcrdcf.2367 Posted: Fri Sep 27 19:06:31 1985 Date-Received: Mon, 30-Sep-85 23:48:09 EDT References: <668@ihu1h.UUCP> Reply-To: curt@sdcrdcf.UUCP (Curt Dodds) Distribution: na Organization: System Development Corp. R+D, Santa Monica Lines: 52 Keywords: trap .profile In article <668@ihu1h.UUCP> takao@ihu1h.UUCP (John Takao Collier) writes: >Is there a way to get a trap to survive the exec of the shell? >What I want to do is set a trap, exec a shell, continue on with >an interactive session in the exec'ed shell, and have the trap >turned on in the exec'ed shell. > >This comes in handy if you want to set a trap in a .profile, but >want to exec a new shell in the .profile. > >For example, if the following commands are invoked: > >trap 'echo bye' 0 >exec /bin/sh > >the trap disappears. > >I have tried various parameters to the shell, such as "-c" and "-i", >but these experiments have failed, e.g.: > >exec /bin/sh -c 'trap "echo bye" 0' > >will exec the shell, read the string specified by the the "-c" parameter, >reads the trap, then exits the exec'ed shell. I do not want to exit >the shell. > >If you have a solution, be it elegant or ugly, I would very much like to >see it. > >Thanks. >-- > >--- >John Takao Collier ..ihnp4!ihu1h!takao 1-312-979-3278 >AT&T Bell Laboratories, Naperville-Wheaton Road, Naperville, IL 60566 Any time you do an exec you lose whatever you've done up to that point (except the environment I suppose). Sounds like what you want is the following: -------------------------------------------------- trap 'echo bye;sleep 2;trap 0;exit' 0 1 2 3 15 /bin/sh exit -------------------------------------------------- If signals 1,2,3 or 15 occur while /bin/sh is running or if /bin/sh exits the sequence of instructions within single quotes will be executed. -- Curt Dodds sdcrdcf!irdmega!curt Brought to you by Super Global Mega Corp .com