LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to execute csh in sh (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-execute-csh-in-sh-827982/)

ashu talwar 08-23-2010 07:40 AM

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

quanta 08-23-2010 07:46 AM

Try this
Code:

. /path/to/your_script.csh
There is a space between . and /path/to...

ashu talwar 08-23-2010 07:52 AM

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 )

quanta 08-23-2010 10:32 AM

Sorry, I haven't read your question carefully. This link may help you partly understand.

theNbomr 08-23-2010 01:50 PM

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.

RockDoctor 08-23-2010 03:30 PM

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

fajri.ikhlas 08-24-2010 04:09 AM

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

ashu talwar 08-24-2010 04:15 AM

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

ashu talwar 08-24-2010 04:18 AM

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

theNbomr 08-24-2010 12:20 PM

Quote:

#!/bin/sh

/bin/tcsh -cf "source my.csh;echo $xx"
But it does not work, May be I am missing something
It doesn't work because the command '/bin/tcsh -cf "source my.csh;echo $xx"' is a child process of the /bin/sh shell.
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.