how to execute csh in sh
how to execute csh in sh
ie, if I have a script in csh syntax as , ( my.csh ) ################## set x = y setenv xx YY ################## And I have a sh script ( my.sh ) ##################### #!/bin/sh I want to call here the my.csh in such a way that I have access to variables set by the csh script ie. echo $x $xx shoud work from sh ( main script ) ###################### Thanks Ashu |
Try this
Code:
. /path/to/your_script.csh |
Thanks quanta,
But this is not my intent, Please read the query again, as I want these variables accessible to me in my Main script ( my.sh ) |
Sorry, I haven't read your question carefully. This link may help you partly understand.
|
You cannot accomplish what you are trying. The only thing that can interpret the csh commands would be a child C-shell, and as a child process, it cannot affect the environment of the parent. The only conceivable way to accomplish what you want, would be to create a tool/script that translates the the C-shell code into Bourne shell code, and then source the resulting Bourne shell code in the top level shell. In essence, you will be writing a C-shell interpreter for Bash.
--- rod. |
Maybe I'm missing something here, but why not either:
1. set the variables in your (bash) environment 2. write a csh script to do everything do want done |
you cannot accomplish what you are trying. The only thing that can interpret the csh commands would be a child C-shell, and as a child process, it cannot affect the environment of the parent. The only conceivable way to accomplish what you want, would be to create a tool/script that translates the the C-shell code into Bourne shell code, and then source the resulting Bourne shell code in the top level shell. In essence, you will be writing a C-shell interpreter for Bash
|
Thanks Everybody for ur efforts to reply to my post.
Here are my points (**): Dear RockDoctor, Maybe I'm missing something here, but why not either: 1. set the variables in your (bash) environment ** I cannot as it is being set my a third party script ( my.csh ) ** I only know the env variable name 2. write a csh script to do everything do want done ** As I told it is a tird party script, So I can't Dear,theNbomr I undersatnd that a child cannot pass env to parent, But When I source the csh script on my terminal , I have access to these variables in my current shell ( on the terminal command prompt ) So, why not in the script I don;t know how, but , lets give a try . like #!/bin/sh /bin/tcsh -cf "source my.csh;echo $xx" But it does not work, May be I am missing something Dear,Quanta Thanks fo the link , still it does not suffice my need. May be I'll agree , that it is not possible |
What I can guess/Trick is that in
#!/bin/sh /bin/tcsh -cf "source my.csh;echo $xx > somefile" read somefile in Main script Then I can have access to these variables |
Quote:
Your work-around might work for some aspects, if the stdout for the child shell has all of the results that you want. It certainly isn't a general purpose solution to the stated problem. Why not just re-write the C-shell script as a bourne shell script? --- rod. PS fajri.ikhlas: Well stated. Did you figure that out all by yourself? |
All times are GMT -5. The time now is 06:22 PM. |