Newsgroups: comp.unix.wizards Path: utzoo!utgpu!watserv1!watcgl!idallen From: idallen@watcgl.waterloo.edu (Ian! D. Allen [CGL]) Subject: Re: cd failure killing script [Re: Interactive 2.2 File zapper] Message-ID: <1990Aug7.050700.27011@watcgl.waterloo.edu> Organization: University of Waterloo References: <772@essnj1.ESSNJAY.COM> <2108@cirrusl.UUCP> <1990Aug3.022641.28848@cbnewse.att.com> <3819@auspex.auspex.com> <1438@sixhub.UUCP> Date: Tue, 7 Aug 90 05:07:00 GMT Lines: 24 In article <1438@sixhub.UUCP> davidsen@sixhub.UUCP (bill davidsen) writes: > Yes, only ksh gives you the choice of catching the failure. No, I think most any sh or csh shell will let you catch the failure, but you have to put the failing command in a subshell. Even if you're stuck with a cd that kills your shell, you can get by using: ( cd "$1" ) && cd "$1" This puts the first cd in a subshell, which may well die but you don't care since you're only interested in the return code. Of course, this has a small window between the first cd and the second, where things might change, and so your shell may get blown away anyway; but, you hope that happens rarely. The above trick is the only way to test for failure in various other built-in shell commands. I often use: ( trap "" 18 22 ) >/dev/null 2>&1 && trap "" 18 22 because many sh shells don't handle signals above 16, but some do. -- -IAN! (Ian! D. Allen) idallen@watcgl.uwaterloo.ca idallen@watcgl.waterloo.edu [129.97.128.64] Computer Graphics Lab/University of Waterloo/Ontario/Canada