Operating System - HP-UX
1821638 Members
3095 Online
109633 Solutions
New Discussion юеВ

running a csh script from a ksh script, and staying in the same shell...

 
caroline_6
New Member

running a csh script from a ksh script, and staying in the same shell...

I have a ksh script from where I have to run another script from there. I need this script to run in the same shell.
My problem is that I dont know if the script, which is a parameter, is in ksh or csh.
In ksh there is no problem since I can just write ". scriptToRun".
But if the script is in csh, how can I make "source" on it?
Thanx
8 REPLIES 8
harry d brown jr
Honored Contributor

Re: running a csh script from a ksh script, and staying in the same shell...

from the ksh shell you don't, but if you were in a csh shell then you would "source filename".

the solution is to not write stuff in csh's

live free or die
harry
Live Free or Die
Rodney Hills
Honored Contributor

Re: running a csh script from a ksh script, and staying in the same shell...

ksh code is incompatible with csh code. If you are running a ksh script, you can't "source" in a csh script and expect it to work. The script will be interpretted by ksh and probabily not work.

Why is it important that the csh script run in the same shell as your ksh script?

If it is a matter of retaining variables between the 2 scripts, then their are other ways to do.

HTH

-- Rod Hills
There be dragons...
Bill Hassell
Honored Contributor

Re: running a csh script from a ksh script, and staying in the same shell...

The . (dot) command is a directive to the shell to interpret (source) the commands. Normally, all shell scripts should start with the courtesy loader command as in:

#!/usr/bin/ksh

but in the case of sourcing a file, csh will read the commands in the ksh script and interpret them accordingly. In csh, the commnand is source as in:

source scriptToRun

I would make sure every script is correctly written with the above header. Ideally, csh should never be used for server work. Do you have an example of the ksh scriptToRun?


Bill Hassell, sysadmin
Mark Greene_1
Honored Contributor

Re: running a csh script from a ksh script, and staying in the same shell...

If you need a reference for management or other admins as to why you shouldn't script in csh, see here:

http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/

mark
the future will be a lot like now, only later
caroline_6
New Member

Re: running a csh script from a ksh script, and staying in the same shell...

Hi all

Thanx for the quick answers.
Ok...why do I want to run a csh script when mine is in ksh?
Because the 2nd script is given by the client, to initialize the environment, and I did not want to ask him to write like this or like that.
What is important for me, is to get in the ksh parent script, my script, all the variables that were initialized in the client script that I have to run...without caring if the client script is written in csh, ksh or something else...
any idea how I can export to my shell the variables of the 2nd script, without caring which kind of script it is?
I have the feeling that there is no way for that and that I'll have to write in the release notes that the script should be written in ksh...:-(
Rodney Hills
Honored Contributor

Re: running a csh script from a ksh script, and staying in the same shell...

If the csh script is being used to set up environmental variables, then you could pass the variables to your ksh script via the following scenario-

client.csh
----------
set myvar1=hello
set myvar2=world

your.csh
--------
source client.csh
tmpname=/tmp/dummyfile
echo "myvar1=$myvar1" >$tmpname
echo "myvar2=$myvar2" >>$tmpname

your.ksh
--------
#!/usr/bin/ksh
csh your.csh
. /tmp/dummyfile

This works by saving the environment variables into a /tmp file and then sourcing that file into the ksh environment.

HTH

-- Rod Hills
There be dragons...
caroline_6
New Member

Re: running a csh script from a ksh script, and staying in the same shell...

Hi Rod

Well, if I knew what are the variables initialized, I was doing that...But I have no idea...
I guess there is no way to export the variables of a csh script, from a ksh script, without knowing the name of those variables...

Thanx anyway
Rodney Hills
Honored Contributor

Re: running a csh script from a ksh script, and staying in the same shell...

Here is something that will get all the variables.

echo "source ttt\nset" | csh | sed -e 's/\t/=/' -e '/^path/d' >/tmp/dumyfile
. /tmp/dumyfile

This will slurp in all variables generated by the csh script.

HTH

-- Rod Hills

(PS- Points are a way to indicate how well a solution fits your problem.)
There be dragons...