Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!rutgers!mcdchg!laidbak!daveb From: daveb@i88.isc.com (Dave Burton) Newsgroups: comp.unix.questions Subject: ksh != sh on traps Keywords: ksh, sh, trap, exit, compatible Message-ID: <1990Feb15.204949.14177@i88.isc.com> Date: 15 Feb 90 20:49:49 GMT Sender: daveb@laidbak.i88.isc.com Organization: Interactive Systems nee Lachman Associates Lines: 44 The 88b version of ksh was changed in a way that, to my eyes, is broken. Below, ksh = 11/16/88b, oksh = 06/03/86, and sh = SunOS 3.5 /bin/sh. Script started on Thu Feb 15 14:18:59 1990 -------------------1$ cat x : trap "echo doing trap 0" 0 trap "echo doing trap 1" 1 die() { trap echo "function: die()" exit 1 } echo "main body" die echo "end of main" exit 2 -------------------2$ sh x main body 0: echo doing trap 0 1: echo doing trap 1 function: die() doing trap 0 -------------------3$ oksh x main body 0:echo doing trap 0 1:echo doing trap 1 function: die() doing trap 0 -------------------4$ ksh x main body function: die() -------------------5$ ^D script done on Thu Feb 15 14:19:23 1990 The KornShell book is self-contradictory on this point: cf ppg 150-151 & 204, and I cannot find any good reason to fathom such a change. Perhaps someone else has an answer (beyond "ksh is broken")? What about workarounds that are compatible with both sh and ksh? -- Dave Burton uunet!ism780c!laidbak!daveb