[comp.unix.questions] Executing a script with a specific shell.

johnb@lakesys.lakesys.com (John C. Burant) (12/30/89)

Is there a way to make a file be executed by a specific shell from within
that file (meaning, not setting an alias to sh filename)...

I'm using csh as my reular shell, and I need a file to be executed by sh,
not csh, and this is not a regular script that would automatically be 
executed with sh by typing its name - it's run with csh.  

Thanks.
-John



-- 
John C. Burant | johnb@lakesys.lakesys.com    
Glendale, Wisc | johnb@lakesys.UUCP         
(414) 228-7915 | uunet!marque!lakesys!johnb 

cpcahil@virtech.uucp (Conor P. Cahill) (12/30/89)

In article <1483@lakesys.lakesys.com>, johnb@lakesys.lakesys.com (John C. Burant) writes:
> I'm using csh as my reular shell, and I need a file to be executed by sh,
> not csh, and this is not a regular script that would automatically be 
> executed with sh by typing its name - it's run with csh.  


Place a:

	#!/bin/sh

as the first line of the shell file.  This always works under BSD unix and
if your primary shell is the csh it will work under system V.
-- 
+-----------------------------------------------------------------------+
| Conor P. Cahill     uunet!virtech!cpcahil      	703-430-9247	!
| Virtual Technologies Inc.,    P. O. Box 876,   Sterling, VA 22170     |
+-----------------------------------------------------------------------+

dbrooks@osf.org (David Brooks) (01/05/90)

In article <1989Dec30.122215.2199@virtech.uucp>, cpcahil@virtech.uucp
(Conor P. Cahill) writes:
> In article <1483@lakesys.lakesys.com>, johnb@lakesys.lakesys.com (John
C. Burant) writes:
> > I'm using csh as my reular shell, and I need a file to be executed by sh,
> 
> Place a:
> 
> 	#!/bin/sh
> 
> as the first line of the shell file.  This always works under BSD unix and
> if your primary shell is the csh it will work under system V.

It doesn't work if you are dealing with a program that explicitly
executes your script using its own idea of the very best shell, and
you want the script to work under other circumstances also (I had
problems with xdm and xmh that way).

I saw something like:

	export foo || exec /bin/sh $0 $*

which will do what you want.  It does issue an error message and
doesn't take account of ksh; can anyone do better?
-- 
David Brooks				dbrooks@osf.org
Open Software Foundation		uunet!osf.org!dbrooks

jde@everex.UUCP (-Jeff Ellis) (01/05/90)

In article <1989Dec30.122215.2199@virtech.uucp> cpcahil@virtech.uucp (Conor P. Cahill) writes:
>Place a:
>	#!/bin/sh
>as the first line of the shell file.  This always works under BSD unix and
>if your primary shell is the csh it will work under system V.

Well is the AT&T SYSV.3.2 systems I have tried that will NOT work.
As per the manual it says that when using csh if the first char in the first
line of a script file is a "#" then csh thinks it will be a csh script.
If this is not true it will invoke sh to run the script. If sh is your
shell then the "#" is treated as a comment. I know I have had to change
a number of files that come with ESIX System V that followed the BSD style
to get them to work under C-Shell......

-- 
Jeff Ellis		ESIX SYSTEM/V A Division Everex Systems Inc.
			US Mail: 1923 St. Andrew Place, Santa Ana, CA 92705
			UUCP:    uunet!zardoz!everex!jde
			Voice: (714) 259-3000 FAX:(714) 259-3010

cpcahil@virtech.uucp (Conor P. Cahill) (01/06/90)

In article <458@everex.UUCP>, jde@everex.UUCP (-Jeff Ellis) writes:
> In article <1989Dec30.122215.2199@virtech.uucp> cpcahil@virtech.uucp (Conor P. Cahill) writes:
> >Place a:
> >	#!/bin/sh
> >as the first line of the shell file.  This always works under BSD unix and
> >if your primary shell is the csh it will work under system V.
> 
> Well is the AT&T SYSV.3.2 systems I have tried that will NOT work.
> As per the manual it says that when using csh if the first char in the first
> line of a script file is a "#" then csh thinks it will be a csh script.

I'm not sure about ESIX, but it sounds like there is a bug there.  In 386/ix
the csh will interpret the #! correctly.

The following shell will produce the indicated output:

	% cat t.sh
	#!/bin/echo hello
	VAR=test
	echo $VAR
	% t.sh
	hello t.sh
	%

So /bin/echo was run with hello and the name of the shell as arguments.
-- 
+-----------------------------------------------------------------------+
| Conor P. Cahill     uunet!virtech!cpcahil      	703-430-9247	!
| Virtual Technologies Inc.,    P. O. Box 876,   Sterling, VA 22170     |
+-----------------------------------------------------------------------+