calling csh script from ksh shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting calling csh script from ksh shell
# 1  
Old 09-03-2008
calling csh script from ksh shell

hi, I have a csh script, which has

Code:
setenv X xyz etc

My shell is korn

Is there some way I can "source" this to have the variables in my current korn shell?

thanks
# 2  
Old 09-03-2008
Hi.

Here is one way. Start with a csh script and source the script that has your setenv defined. That will create environment variables that can be passed to children processes. Then in the first script call the Korn shell script. Here's how it would work with tcsh and pdksh:
Code:
#!/usr/bin/env tcsh

# @(#) first.csh        Demonstrate calling Korn shell script.

echo
echo "(Versions displayed with local utility version)"
sh -c "version >/dev/null 2>&1" && version "=o" tcsh
echo

source second.csh
./s1

exit 0

and second:
Code:
setenv X xyz

and the Korn script:
Code:
#!/bin/ksh -

# @(#) s1       Demonstrate inheriting environment variables from csh.

echo
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version "=o" $(_eat $0 $1)
set -o nounset

echo
echo " Results:"
echo " variable X is \"$X\""

exit 0

If you execute ./s1 by itself, we expect that the variable will not be defined:
Code:
% ./s1

(Versions displayed with local utility "version")
Linux 2.6.11-x1
pdksh 5.2.14 99/07/13.2

 Results:
./s1[12]: X: parameter not set

However, if you execute the first csh script, you get:
Code:
% ./first.csh

(Versions displayed with local utility version)
Linux 2.6.11-x1
tcsh 6.13.00


(Versions displayed with local utility "version")
Linux 2.6.11-x1
pdksh 5.2.14 99/07/13.2

 Results:
 variable X is "xyz"

You might also experiment with creating a function setenv which takes parameters variable-name and value, etc.

Best wishes ... cheers, drl
# 3  
Old 09-03-2008
Quote:
Originally Posted by JamesByars
hi, I have a csh script, which has

Code:
setenv X xyz etc

My shell is korn

Is there some way I can "source" this to have the variables in my current korn shell?

thanks
I'd go with a function to handle this AS LONG AS there are no other csh-specific lines in the file.
Code:
setenv() { parm=$1; shift; eval '\${$parm}="$*"'; }

(I'm not sure that's 100% correct.) Then source it with
Code:
#!/bin/ksh
. somefile.csh
printenv

The other thing you can do is pass the source file through awk and read the input into eval:
Code:
#!/bin/ksh

eval `awk somefile.csh '/^setenv/ { $1=""; var=$2;$2=""; print var "=" $0; }'`
printenv

Again, not sure if it's 100% correct. There might be some spaces in the output of the awk command that should be quoted and such.
# 4  
Old 12-18-2008
This is working for me: had to grep some junk out of printenv...

environment.ksh:

#!/usr/bin/ksh
for i in `csh -c 'source environment.csh; printenv | grep -v \% | grep \='`
do
eval export $i
done

------

source this file, as in " . environment.ksh"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Oracle/SQLPlus help - ksh Script calling .sql file not 'pausing' at ACCEPT, can't figure out why

Hi, I am trying to write a script that calls an Oracle SQL file who in turns call another SQL file. This same SQL file has to be run against the same database but using different username and password at each loop. The first SQL file is basically a connection test and it is supposed to sort... (2 Replies)
Discussion started by: newbie_01
2 Replies

2. Shell Programming and Scripting

Pass C shell array to another C shell script(csh) and shell(sh)

Dear Friends, Please help me on this my script name is send.csh In this i have written the statement like this set args = ( city state country price ) I want to pass this array to another c shell called receiver.csh. and i want to use it in this c shell or how to pass to... (2 Replies)
Discussion started by: SA_Palani
2 Replies

3. Shell Programming and Scripting

Calling Oracle stored procedure from ksh script

Friends, I'm newbie with ksh so wanting some help.... 1. I'm trying to call oracle stored procedure from ksh script by taking variable value from runtime, feed into script and execute procedure. 2. Put name1 and name2 value from script run replacing $3 & $4 I'm trying to put name1 in... (4 Replies)
Discussion started by: homer4all
4 Replies

4. Shell Programming and Scripting

Calling SQL script from ksh job and send mail on some error.

Hi, I am trying to call sql script from ksh job with parameters.The parameters passed from ksh job will be used in SELECT query in sql file to SPOOL the data in extract file.My questions are: 1) How to call a sql script from ksh job with parameters? 2) How to use the parameter in sql file to... (1 Reply)
Discussion started by: anil029
1 Replies

5. Shell Programming and Scripting

calling expect script in ksh is failing via cron

I'm calling an expect script via a ksh script in cron and it is failing. The script runs fine if i run it manually. Does anyone know if it is an issue with compatibilty and if there is a way around it? (2 Replies)
Discussion started by: bhatia
2 Replies

6. Shell Programming and Scripting

Get return value from PERL script calling from KSH

All: I am calling a PERL script from KSH. I need specific codes to be returned by the PERL Script. For ex: Ksh ----- result=`test.pl $FILE` My idea is to get the value of result from the test.pl, by specifically making the test.pl to print the return code. Since I had some other print... (1 Reply)
Discussion started by: ucbus
1 Replies

7. Shell Programming and Scripting

passing a variables value from the called script to calling script using ksh

How do i get the value of the variable from the called script(script2) to the calling script(script1) in ksh ? I've given portion of the script here to explain the problem. Portion of Script 1 ============= ----- ----- tmp=`a.ksh p1 p2 p3` if then # error processing fi -----... (10 Replies)
Discussion started by: rajarkumar
10 Replies

8. Shell Programming and Scripting

calling a ksh script present in different unix box

Hi , I have a shell script which does some calling of procedures once all the procedures are called I need to start another ksh script which is present on a different unix box How can this be done ? Do I need to open a telnet session to connect to that box in my first script and... (1 Reply)
Discussion started by: Navatha
1 Replies

9. Shell Programming and Scripting

How to define array in Bourne shell , csh & ksh

Dear friends... Kindly if any one can help me to know the differences in definning & retreiving data from arrays in the sh,csh & ksh. I always facing problems in this issue. thanks...:) BR (3 Replies)
Discussion started by: ahmad.diab
3 Replies

10. Shell Programming and Scripting

Calling C from within a csh script

After I compile a C program, when I run it from a C shell script, it does not print out the results. e.g: myCFile.c: main(){printf("Hey");} myCshScript: myCFile This does not output "Hey" to the terminal window. I am not even sure if it is executed or not. What should I do to see the... (2 Replies)
Discussion started by: barisgultekin
2 Replies
Login or Register to Ask a Question