[comp.unix.questions] How can shell scripts be shared by different shells?

andy@syma.sussex.ac.uk (Andy Clews) (04/05/91)

A problem has arisen at our site, whereby most of our users use Csh but a
few others use Sh derivatives (i.e.  Ksh and Bash).  Some users are
expressing an interest in changing to Ksh from Csh, a move which we tend to
encourage because Ksh is generally considered better than Csh. 

Some users, who are part of a course, and who are Csh users, have a "source"
command in their .login files which takes commands from a central C-shell
file, which does things like setting special paths and environment variables
and so on.

The problem is: supposing any of these users want to switch to Korn shell?
If they make an equivalent .profile file, and put ". shellfile" instead of
"source shellfile" in it, then Ksh naturally won't understand the Csh
commands in the central "shellfile".

Does anyone know of any clever kludges that can be made to this central
shellfile, which could allow Ksh or Csh to be able to source it? I thought
of putting a test at the top, but of course tests are different in Csh
and Ksh.....

I hope I haven't missed something in TFM....
-- 
Andy Clews, Computing Service, Univ. of Sussex, Brighton BN1 9QN, England
JANET: andy@uk.ac.sussex.syma        BITNET: andy%syma.sussex.ac.uk@uk.ac

pfalstad@phoenix.Princeton.EDU (Paul Falstad) (04/07/91)

andy@syma.sussex.ac.uk (Andy Clews) wrote:
>Does anyone know of any clever kludges that can be made to this central
>shellfile, which could allow Ksh or Csh to be able to source it? I thought
>of putting a test at the top, but of course tests are different in Csh
>and Ksh.....

Do something like this:

export PATH && . kshscript && exit
source cshscript

Then create two files named 'kshscript' and 'cshscript' with appropriate
commands in each.  Or, just include the csh commands after the 'export'
line.

Why can't you just have two separate shellfiles, one for csh users and one
for ksh users, and just have each person source/. the appropriate file?

--
Paul Falstad, pfalstad@phoenix.princeton.edu | 10 PRINT "PRINCETON CS"
[Your blood pressure just went up.]          | 20 GOTO 10
Princeton University would like to apologize to everyone for this article.

gwyn@smoke.brl.mil (Doug Gwyn) (04/07/91)

In article <4805@syma.sussex.ac.uk> andy@syma.sussex.ac.uk (Andy Clews) writes:
>Does anyone know of any clever kludges that can be made to this central
>shellfile, which could allow Ksh or Csh to be able to source it?

Perhaps a slightly different approach would be better -- how about instead
(from ksh) sourcing a Cshell emulator, feeding it the desired script as an
argument?  If you don't have a cshell emulator and don't know where to get
one, drop me a note and I'll send you the one I have lying around (unused
but kept as a curiosity piece).  I didn't develop it myself, but since it
was posted in a publice newsgroup I feel free to redistribute it.