[comp.unix.i386] Forcing /bin/sh in a script under V/386 3.2 Korn shell

tneff@bfmny0.UUCP (Tom Neff) (07/08/89)

I use Korn shell and am happy with it, but I want certain shell
scripts to be intepreted by the Bourne shell instead.  There is
already a mechanism by which CSH(1) figures out to spawn /bin/sh
on a script rather than interpreting itself, namely putting a
colon ':' as the first line.

	% cat > xxx
	:
	ps
	^D
	% chmod a+x xxx
	% xxx
	   PID TTY      TIME COMMAND
	 27632 console  0:00 csh
	 27640 console  0:00 sh
	 27641 console  0:00 ps

What I want to know is, is there any way to do this under K-shell?
The colon certainly doesn't work, and neither does

	#! /bin/ksh

or anything else I've tried.  Sure would be nice.
-- 
"My God, Thiokol, when do you     \\	Tom Neff
want me to launch -- next April?"  \\	uunet!bfmny0!tneff

cks@ziebmef.uucp (Chris Siebenmann) (07/12/89)

In article <14445@bfmny0.UUCP> bfmny0!tneff@uunet.UU.NET (Tom Neff) writes:
| I use Korn shell and am happy with it, but I want certain shell
| scripts to be intepreted by the Bourne shell instead.  

 On a BSD Unix, one could put "#! /bin/sh" at the start of your script
and it would work. Unfortunately, System V doesn't have this (and
worse yet, your vendor has gratuitusly hacked csh so many scripts will
break under it), so the best substitute (swiped from Perl v2's
Configure script) is:

	(alias) >/dev/null 2>&1 && (exec /bin/sh $0 ${1+"$@"})

-- 
	"Oh BLESS you, sir! The ANGEL OF DEATH was after me just as SURE as
	 you're standing there, yes he WAS!"
Chris Siebenmann		uunet!{utgpu!moore,attcan!telly}!ziebmef!cks
cks@ziebmef.UUCP	     or	.....!utgpu!{,ontmoh!,ncrcan!brambo!}cks

tbertels@cipc1.Dayton.NCR.COM (Tom Bertelson) (07/15/89)

In article <1989Jul11.225839.14835@ziebmef.uucp> cks@ziebmef.uucp (Chris Siebenmann) writes:
> On a BSD Unix, one could put "#! /bin/sh" at the start of your script
>and it would work. Unfortunately, System V doesn't have this (and
>worse yet, your vendor has gratuitusly hacked csh so many scripts will
>break under it), so the best substitute (swiped from Perl v2's
>Configure script) is:
>
>	(alias) >/dev/null 2>&1 && (exec /bin/sh $0 ${1+"$@"})

A minor nit.  If you have an interactive program called "alias" on
your system (as I discovered here) you could be in for a surprise.
Try instead

	(PATH= alias) >/dev/null 2>&1 && (exec /bin/sh $0 ${1+"$@"})

Some day I'll send this off to Larry Wall ...
-- 
Tom Bertelson			DISCLAIMER:  My opinions are my own and
Tom.Bertelson@Dayton.NCR.COM	in no way reflect those of my employer.
...!uunet!ncrlnk!cipc1!tbertels