LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 07: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, 07:46 AM   #2
quanta
Member
 
Registered: Aug 2007
Location: Vietnam
Distribution: RedHat based, Debian based, Slackware, Gentoo
Posts: 724

Rep: Reputation: 101Reputation: 101
Try this
Code:
. /path/to/your_script.csh
There is a space between . and /path/to...
 
Old 08-23-2010, 07: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, 10:32 AM   #4
quanta
Member
 
Registered: Aug 2007
Location: Vietnam
Distribution: RedHat based, Debian based, Slackware, Gentoo
Posts: 724

Rep: Reputation: 101Reputation: 101
Sorry, I haven't read your question carefully. This link may help you partly understand.
 
Old 08-23-2010, 01:50 PM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
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, 03:30 PM   #6
RockDoctor
Senior Member
 
Registered: Nov 2003
Location: Minnesota, US
Distribution: Fedora, Ubuntu, Manjaro
Posts: 1,791

Rep: Reputation: 427Reputation: 427Reputation: 427Reputation: 427Reputation: 427
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, 04: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, 04: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, 04: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, 12:20 PM   #10
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
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 12:21 PM.
 
  


Reply



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 05:48 PM
csh nirmaltom Programming 1 05-18-2007 08:07 AM
help with quotes in csh kanesee Programming 1 05-08-2007 07:10 PM
Csh or Bsh max_linuxquesti Programming 4 12-26-2002 01:17 PM
csh zaza Linux - Newbie 6 05-21-2002 06:26 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:49 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
Open Source Consulting | Domain Registration