LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 05-11-2009, 09:48 AM   #1
anindyarc
LQ Newbie
 
Registered: Apr 2009
Posts: 1

Rep: Reputation: 0
Unhappy converting a c shell file to a bash shell file


I have bash shell, and I need to source a file from .bashrc file. but that file is a c shell file i.e it has commands like setenv etc. I need to change the whole file to a bash file. how can i do that? am new to linux. help me.
 
Old 05-11-2009, 02:17 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,714
Blog Entries: 14

Rep: Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039
You may not need to convert at all.

Linux has csh available in addition to bash. To "source" a script and use its variables you simply type ". <script>". Note that there is a space after the dot and before the script name.

To insure the csh file/script is running csh you just add an interpreter line to the beginning of it similar to:
#!/bin/csh
(/bin/csh is the location my CentOS box - it may be different on whatever distro you're running).

I don't know of any csh to bash converters but if you do a Google search you may find something.
 
Old 05-11-2009, 03:26 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by anindyarc View Post
I have bash shell, and I need to source a file from .bashrc file. but that file is a c shell file i.e it has commands like setenv etc. I need to change the whole file to a bash file. how can i do that? am new to linux. help me.
How long/complex is your file?

If it's just a handful of setenv statements conversion
is trivial, all you need to do is to replace a

setenv XXXX blahblah
with
export XXXX=blahblah

One could just about do that with sed ;}

Code:
echo "setenv XXXX This is XXXX' contents" | sed -r 's/^[[:space:]]*setenv ([[:alnum:]]+) (.*)/export \1="\2"/'             
export XXXX="This is XXXX' contents"


Cheers,
Tink
 
  


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
BASH SHELL , how to copy all file in dir1 to dir3 CheeSen Programming 15 11-02-2008 06:11 AM
Bash shell file... echo on? carlos_vcan Linux - Newbie 3 06-12-2008 10:10 PM
File Creation: bash shell stapletone Linux - Newbie 2 09-24-2006 12:35 PM
end of file in bash shell manojg Linux - Newbie 4 03-09-2006 10:11 AM
converting .tif images to an animated .gif file (Red Hat 7.2, bash shell) illiniguy3043 Linux - General 0 06-01-2004 01:07 PM


All times are GMT -5. The time now is 08:28 PM.

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