> I need to "source" a csh script from a ksh script. Is there any way to
> do this? For example:
> echo test1
> exec csh
> source csh_script_name
> echo test2
> When this executes, it fails to source the csh_script_name script. The
> csh_script_name script attempts to set environment variables.
> Is there any way to do this?
Hmmm. Lots of csh questions this morning. :-) The general problem is
that when you "exec" csh, it takes over the current shell (hence, it is
in a sub-shell until 'exit' is called, and then all the environment
variables disappear). I'll assume that what you want to do is export
some csh variables into the ksh environment. The only reliable way I can
think of doing this is to mangle the csh file with sed into a ksh
script, then write that to a temp file. Your ksh script would then
source that script. I would imagine that this could get very complicated
for a non-trivial script. Here goes:
The sed fragment attempts to change every occcurance of setenv to
export, then change every ' = ' to a '=' to make the assignments valid.
e.g. assuming a csh_script_name of the form:
#! /bin/csh -f
setenv testarg1 = "this is test 1"
setenv testarg2 = "this is test
Sample code might be...
sed 's/setenv/export/; s/ = /=/' csh_script_name >
[ ! -f mangled_csh_script.tmp ] && echo "Eek! Bailing out..." && exit 1
. mangled_csh_script.tmp # '.' means 'source'
rm -f mangled_csh_script.tmp
Very messy, consumes a lot of resources, and is very fallible. A better
approach in the long run might be just to convert the csh file into a
Sorry I couldn't be of more help. Csh isn't really my forte. ;-)