Forcing /bin/sh in a script under V/386 3.2 Korn shell

CME Ned Nowotny ned at pebbles.cad.mcc.com
Wed Jul 19 09:12:36 AEST 1989


In article <14463 at bfmny0.UUCP> tneff at bfmny0.UUCP (Tom Neff) writes:
>My thanks to all who have responded via mail or news posting to my
>question about forcing the Korn shell (KSH) to run a script using the
>Bourne shell (SH) instead of itself.  There have been no completely
>satisfactory answers, but I will summarize the State Of What Is Known.
>
... Lines Deleted ...
>
> * There is an exact analogue to what I want for the C-Shell (CSH):
>   if you put a colon ":" as the first line of a script, CSH will
>   detect it and automatically spawn SH instead of itself to execute
>   the script.  (This is the way AT&T documents it; some users claim
>   that putting *anything* other than "#" at the start of the first
>   line does it, or that a blank first line does it, but I recommend
>   sticking with the AT&T convention to avoid blowing up on someone's
>   weird CSH variant.)  You can see this done at the start of most of
>   the AT&T supplied system shell scripts like installpkg and shutdown
>   and even basename.  But no, it does not convince KSH.  To prove this,
>   create the script
>
>	:
>	ps -f
>

There is some missing history here.

In the old days (around Version 6 or 7 and before), the Bourne shell did not
have a comment character, but it did have the null command, ":".  Now, the null
command was useful in several ways (e.g. ":" is a trivial true command - this
was important when "true" was not a built-in and required a new process to be
forked).  In fact, one of the most useful things you could do with ":" was to
comment your shell script since ":" does nothing with the arguments (a.k.a.
comment string) that you may provide it.  While modern Bourne shells include
both the "#" comment character and a built-in "true", they also still include
the null command, ":".  As a consequence, the Korn shell also includes the
null command and its original semantics.  So no, it can not be used to
distinguish a Bourne shell script from a Korn shell script.

On the other hand, the C shell did use the "#" as a comment character in
the early days.  As a result, shell scripts that started with a "#" were
almost certainly C shell scripts beginning with a comment (as all good
code should).  Therefore, the C shell could be preferentially forked just
by determining whether the script began with a "#".  While BSD went on to
provide the more general script mechanism using "#!", AT&T never really
did much better than use the old comment character trick.  This even after the
Bourne shell gained the "#" comment character and despite the inclusion
of the C shell by UNIX vendors.  (Of course, AT&T did not include C shell
as part of its stock UNIX distribution for many years, so the conflict was
a non-problem from their point of view.)

So while I can't provide a solution to your problem given that your system
does not support the "#!" mechanism, I hope this history may at least explain
why things are the way they are (mostly, AT&T suffered from NIH - and yes,
BSD suffered from "featuritis").  Errors in the above will no doubt be quickly
corrected.


Ned Nowotny, MCC CAD Program, Box 200195, Austin, TX  78720  Ph: (512) 338-3715
ARPA: ned at mcc.com                   UUCP: ...!cs.utexas.edu!milano!cadillac!ned
-------------------------------------------------------------------------------
"We have ways to make you scream." - Intel advertisement in the June 1989 DDJ.



More information about the Comp.unix.questions mailing list