Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 09-16-2015, 12:21 PM   #1
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, 12:36 PM   #2
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,704

Rep: Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270
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:

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 12:39 PM.
Old 09-17-2015, 08:09 AM   #3
LQ Newbie
Registered: Sep 2015
Posts: 2

Original Poster
Rep: Reputation: Disabled

Thanks - that worked!


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

All times are GMT -5. The time now is 03:22 PM.

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