Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site brl-tgr.ARPA Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!brl-tgr!gwyn From: gwyn@brl-tgr.ARPA (Doug Gwyn ) Newsgroups: net.sources Subject: Re: "nmkdir" in the Bourne shell at a Unix machine near you. Message-ID: <1193@brl-tgr.ARPA> Date: Tue, 3-Sep-85 14:42:32 EDT Article-I.D.: brl-tgr.1193 Posted: Tue Sep 3 14:42:32 1985 Date-Received: Thu, 5-Sep-85 08:25:54 EDT References: <1052@sdcsvax.UUCP> <309@cxsea.UUCP> <226@tikal.UUCP> <2558@pegasus.UUCP> Organization: Ballistic Research Lab Lines: 95 > > if cd $d > > ... > I think in the bourne shell a bad cd will terminate the shell script > no matter what its return code. Therefore, as soon as a bad cd occurs, > termination before any test. There is a simple way around this; use a subshell as in (cd $d). By way of illustration, here the the .funcs file that I source in my .profile. (Warning: the suspend() function is for the BRL SVR2 job-control Bourne shell and will not work with the AT&T SVR2 shell.) # shell functions DIRSTACK=... # for pushd, popd ch(){ if [ $# -lt 1 ] then cd else cd $1 fi PS1=`uname`:`pwd`' $ ' } j(){ (set +u; exec jove $*); } l(){ (set +u; exec ls -bCF $*); } not(){ $* if [ $? -eq 0 ] then return 1 else return 0 fi } popd(){ set $DIRSTACK if [ $# -ge 2 ] then DIRSTACK="$*" ch $1 set $DIRSTACK # ch clobbered $* shift DIRSTACK="$*" fi } print(){ (set +u; pr $* | lpr); } pushd(){ DIRSTACK=`pwd`" $DIRSTACK" if [ $# -lt 1 ] then set $HOME fi if (cd $1) then cd $1 >&- echo $DIRSTACK PS1=`uname`:`pwd`' $ ' else popd fi } if not pdp11 then suspend(){ case "$-" in *J*) set +j kill -18 $$ set -J ;; *) kill -18 $$ # SIGSTOP ;; esac } readonly suspend fi swapd(){ DIRSTACK=`pwd`" $DIRSTACK" set $DIRSTACK if [ $# -ge 3 ] then DIRSTACK="$*" ch $2 set $DIRSTACK # ch clobbered $* DIRSTACK="$1" shift 2 DIRSTACK=$DIRSTACK" $*" echo $DIRSTACK else shift DIRSTACK="$*" echo 'swapd: No previous directory' >&2 return 1 fi } readonly ch j l popd print pushd swapd