>The following is the text of a ksh script called "foo":
>#! /bin/ksh
>function x
>{
> echo "This is Ksh!"
>}
>If I say "sh foo" it produces the following output:
>UX:sh (x): ERROR: function: not found
>This is Ksh!
>This is Ksh!
>What is the difference between the two invocations "foo" and "sh foo"?
versions of the system the kernel realizes the first line of the file is
a hashbang and it starts up the indicated interpreter to read the file foo.
( On some systems, e.g. Minix, the exec call is unable to recognize hashbangs.
In such cases, and with some shells, it is possible to build this feature in
at the shell level.)
In the invocation "sh foo" the Bourne shell reads foo and interprets the first
line as a comment.
There is a standard shell-programming technique for dealing with scriptsQuote:>And if I write a ksh script how do I ensure that it works whether users are
>typing "sh foo" or simply "foo"?
intended for other shells than the one actually reading them. For example,
the following line from Pnews
export PATH || (echo "OOPS, this isn't sh. Desperation time. I will feed
myself to sh."; sh $0; kill $$)
aims to prevent the script from being run in csh. Your problem is
somewhat different in that ksh is a superset of sh. I don't know ksh,
but you should be able to replace "export PATH" with some construction
that is guaranteed to fail in sh but succeed in ksh.
--
************************************************************************
Terry R. McConnell Mathematics/304B Carnegie/Syracuse, N.Y. 13244-1150
************************************************************************