Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!clyde!ho95e!wcs From: wcs@ho95e.ATT.COM (Bill.Stewart) Newsgroups: comp.unix.questions Subject: Re: why does this script... ( : and # ) Message-ID: <1500@ho95e.ATT.COM> Date: Tue, 23-Jun-87 14:48:32 EDT Article-I.D.: ho95e.1500 Posted: Tue Jun 23 14:48:32 1987 Date-Received: Thu, 25-Jun-87 03:54:13 EDT References: <913@rtech.UUCP> <7062@mimsy.UUCP> <767@bsu-cs.UUCP> Reply-To: wcs@ho95e.UUCP (46133-Bill.Stewart,2G218,x0705,) Organization: AT&T Bell Labs 46133, Holmdel, NJ Lines: 32 Keywords: #!, csh, ksh In article <767@bsu-cs.UUCP> dhesi@bsu-cs.UUCP (Rahul Dhesi) writes: : In several articles strategies for ensuring execution by a specific shell : are discussed. : Larry Wall's terrific installation scripts for patch and rn use the : equivalent of following line to force execution by sh: : export PATH || (echo "OOPS, trying again..."; sh $0; kill $$) : There ought to be a way of doing the same thing for other shells. The : penalty is the extra fork (or is it TWO extra forks?). I generally write all my scripts in Bourne Shell, because I know they'll work (relatively) portably. When it's important to use ksh, I use the following: if [ "$RANDOM" = "$RANDOM" ] then ## recovery script to feed itself to ksh ksh -c "$0 $*" exit "$?" fi The simpler approach of checking $SHELL doesn't work; SHELL is exported, and some programs will drop into /bin/sh by default. ksh updates $RANDOM each time it uses the value, so "$RANDOM" = "$RANDOM" will never be true in ksh, and will (presumably) always be true in other shells. Writing a good recovery script is hard; if the arguments to the program contain white space or metacharacters, the $* will trash them. Sometimes it matters. Is there a good equivalent of this technique for csh? I suppose one could separate the program in to a csh file and a Bourne-shell front-end, : exec csh -c "$0.csh $*" but it would be much nicer to have something self-contained. -- # Bill Stewart, AT&T Bell Labs 2G-202, Holmdel NJ 1-201-949-0705 ihnp4!ho95c!wcs