Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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 )
######################
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.
/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?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.