cd failure killing script [Re: Interactive 2.2 File zapper]
Ian! D. Allen [CGL]
idallen at watcgl.waterloo.edu
Tue Aug 7 15:07:00 AEST 1990
In article <1438 at sixhub.UUCP> davidsen at 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 at watcgl.uwaterloo.ca idallen at watcgl.waterloo.edu
[129.97.128.64] Computer Graphics Lab/University of Waterloo/Ontario/Canada
More information about the Comp.unix.wizards
mailing list