LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 08-23-2010, 08:40 AM   #1
ashu talwar
LQ Newbie
 
Registered: Aug 2010
Posts: 5

Rep: Reputation: 0
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
 
Old 08-23-2010, 08:46 AM   #2
quanta
Member
 
Registered: Aug 2007
Location: Vietnam
Distribution: RedHat based, Debian based, Slackware, Gentoo
Posts: 724

Rep: Reputation: 100Reputation: 100
Try this
Code:
. /path/to/your_script.csh
There is a space between . and /path/to...
 
Old 08-23-2010, 08:52 AM   #3
ashu talwar
LQ Newbie
 
Registered: Aug 2010
Posts: 5

Original Poster
Rep: Reputation: 0
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 )
 
Old 08-23-2010, 11:32 AM   #4
quanta
Member
 
Registered: Aug 2007
Location: Vietnam
Distribution: RedHat based, Debian based, Slackware, Gentoo
Posts: 724

Rep: Reputation: 100Reputation: 100
Sorry, I haven't read your question carefully. This link may help you partly understand.
 
Old 08-23-2010, 02:50 PM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.
 
Old 08-23-2010, 04:30 PM   #6
RockDoctor
Senior Member
 
Registered: Nov 2003
Location: Minnesota, US
Distribution: Fedora, Linux Mint, Ubuntu
Posts: 1,514

Rep: Reputation: 326Reputation: 326Reputation: 326Reputation: 326
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
 
Old 08-24-2010, 05:09 AM   #7
fajri.ikhlas
LQ Newbie
 
Registered: Aug 2010
Posts: 1

Rep: Reputation: 0
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
 
Old 08-24-2010, 05:15 AM   #8
ashu talwar
LQ Newbie
 
Registered: Aug 2010
Posts: 5

Original Poster
Rep: Reputation: 0
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
 
Old 08-24-2010, 05:18 AM   #9
ashu talwar
LQ Newbie
 
Registered: Aug 2010
Posts: 5

Original Poster
Rep: Reputation: 0
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
 
Old 08-24-2010, 01:20 PM   #10
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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?

Last edited by theNbomr; 08-24-2010 at 01:21 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
csh: while read eantoranz Programming 6 07-08-2009 06:48 PM
csh nirmaltom Programming 1 05-18-2007 09:07 AM
help with quotes in csh kanesee Programming 1 05-08-2007 08:10 PM
Csh or Bsh max_linuxquesti Programming 4 12-26-2002 02:17 PM
csh zaza Linux - Newbie 6 05-21-2002 07:26 AM


All times are GMT -5. The time now is 11:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration