I run bash scripts from tcsh shells. I want to set an environment variable in the tcsh shell from a bash script.

The method of doing this, if your parent shell is bash is to source a file, i.e., if I have a file called dog that contains

export $myEnv

then from a bash shell, the command

. dog

will as expected create an envi source dog

then nothing happens. Is there a way to accomplish what I want to do?


  • 1
    What does "will as expected create an envi source dog" mean in English?
    – waltinator
    Commented Apr 13, 2016 at 15:03
  • Sorry, that was a typo. Please see my response to @Serg below. My problem is that I can't find any way to communicate from within a bash script to the parent shell that is running in my xterm. All I need to do is to somehow create an environment variable in the parent tcsh shell from within a bash script. Seems like it should be really easy, rather than impossible.
    – Leo Simon
    Commented Apr 14, 2016 at 0:01

2 Answers 2


You want

export myEnv


export $myEnv

In addition to what Gunnar already noted, export will make the variable available only to that instance of bash shell and its child processes. In addition tcsh and bash syntax differ when it comes to variables.

I would suggest you set a variable in the syntax familiar to tcsh

eagle:~/sergrep> cat var_file.txt
setenv foo "TEST"
eagle:~/sergrep> source var_file.txt
eagle:~/sergrep> echo $foo
  • What you suggested @Serg works fine from tcsh. But my problem is that I need to run the source command from inside a bash script. That is somehow I have to make bash talk to my parent tcsh shell. When I run your var_file.txt from with a bash script, with the command . var_file.txt it returns an error saying that it can't find setenv. That's the essence of my problem.
    – Leo Simon
    Commented Apr 13, 2016 at 23:56
  • @LeoSimon talking to the parent shell is exactly the problem. To the best of my knowledge , there's no way to communicate a variable back to parent. May i ask what is the purpose of such behavior ? Is spawning a child tcsh from script an option ? export will make variables available to children Commented Apr 14, 2016 at 1:48
  • I'm pretty sure that if I could spawn a child tcsh script from within a bash script I'd be fine. The script would do exactly what you said above, i.e., simply setenv foo "TEST". The reason I want to do this that I want my latex scripts to read an environment variable. This variable has a default value. I have a complicated bash script, within which I sometimes want to specify a modified value for this environment variable. That's why I need to do a setenv from within the bash script. Hope this is clear enough?
    – Leo Simon
    Commented Apr 14, 2016 at 7:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .