Does #!/bin/sh work w/tcsh? (was: Re: Shells for SYSV machines)

DoN Nichols dnichols at ceilidh.beartrack.com
Wed Jun 19 09:52:18 AEST 1991


In article <1991Jun17.225245.22105 at agate.berkeley.edu> et at tornado.Berkeley.EDU (Eric Thompson) writes:
>On a related note, I've found that my tcsh binary (from ee.cornell.edu)
>doesn't pay any attention to a "#!/bin/sh" line at the top of a Bourne
>shell script.  This is a pain.

	Since csh is a descendant of csh, which comes from the Berkeley
universe, and Berkeley Unix systems have the KERNEL check for #!, you
wouldn't expect csh (and tcsh) to check for it.

>The workaround I've got going is to set $SHELL and $shell to /bin/sh.
>Then any scripts that are executed use the $shell variable.  I'd rather
>if it would check the top of the script to see which shell to run--if
>it's possible, let me know how, please?  :-)  Thanks.

	The usual workaround in the systems that don't check for #! is to
put as the top line of the script the single character ':' for a script
which needs to be run by /bin/sh (or /bin/ksh for that matter, if it has be
linked to /bin/sh after MVing /bin/sh to something like /bin/sh.OLD).  Csh
and tcsh look at it and say "This isn't a legal command line for me, but
I'll bet that old /bin/sh would love it!".  At the same time, /bin/sh on
some systems will pass the script to /bin/csh if the first line starts with
'#'.

	The problem with this method is that it assumes that there are only
two shells, /bin/sh, and /bin/csh.  When you start tossing in other
shells/interpreters/etc, things get more and more byzantine, as each needs a
way to identify scripts for all others.  Just look at what needs to be done
for perl scripts on systems which don't check for '#!'.

	You don't mention which flavor of AT&T sytems you're dealing with,
and my experience stops at SysVr2 (the UNIX-PC), but I believe that this
still works.  I think that SysVr4 has added the ability to recognize '#!' to
the kernel.  Some pd shells (such as ash, and maybe bash) do their own
checking for '#!'.

	Good Luck
		DoN.

-- 
Donald Nichols (DoN.)		| Voice (Days):	(703) 664-1585
D&D Data			| Voice (Eves):	(703) 938-4564
Disclaimer: from here - None	| Email:     <dnichols at ceilidh.beartrack.com>
	--- Black Holes are where God is dividing by zero ---



More information about the Comp.sys.att mailing list