LinuxQuestions.org
Visit Jeremy's Blog.
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 09-16-2015, 01:21 PM   #1
Aussy
LQ Newbie
 
Registered: Sep 2015
Posts: 2

Rep: Reputation: Disabled
Unhappy Source CSH script from ZSH or BASH


I sometimes run some project scripts that are written for #!/bin/csh. These scripts set up environmental variables (setenv, set, and alias commands). But I am running in ZSH (which is roughly equivalent to BASH).

Is there a good way to either
(a) Source this script from bash/zsh so that the bash/zsh shell will inherit all the variables that the CSH script set, or
(b) Convert the script to a bash/zsh script so that I can run the converted script directly from bash/zsh?

The csh scripts are for a project area that I don't control, and they may possibly change by another user, so I'd like an automated way if possible. Or if the only way to do it is to manually convert the scripts using find-and-replace, then let me know that's the answer. Thanks.
 
Old 09-16-2015, 01:36 PM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,602

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Environmental variables, sort of (if they are global). Aliases, no (different name space).

for environmental variables you end up having to do a chain operation...

Something like a csh "wrapper" script:
Code:
#!/bin/csh

source <csh script of your choice>

exec /usr/bin/bash
Then, to invoke it you do "exec wrapper".

What happens is the exec changes the current shell to csh (which inherets the bash environment variables) to run the wrapper script, the wrapper then includes the csh script which sets up any exported environment variables. Once that is done, the wrapper script then execs bash - which inherets the updated environment.

This is a bit clumsy, but would work for anything other than functions or aliases (which are not passed in the global environment variables - they are for subshells, not processes).

PS. Not sure how well this would work in bashrc - as once you exec the csh, the current shell context will no longer exist.

Last edited by jpollard; 09-16-2015 at 01:39 PM.
 
Old 09-17-2015, 09:09 AM   #3
Aussy
LQ Newbie
 
Registered: Sep 2015
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks!

Thanks - that worked!
 
  


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
converting bash script to csh shell asinghpu Programming 2 12-21-2011 08:24 AM
script: Am I running in bash or zsh? spiralofhope Linux - Software 6 06-15-2009 12:36 AM
converting bash script to csh DJOtaku Programming 8 02-13-2006 06:35 AM
Script for csh or bash unihiekka Programming 5 10-15-2005 10:51 AM
Bash or Zsh reddazz Linux - General 5 05-27-2005 09:16 AM


All times are GMT -5. The time now is 02:31 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