Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to source a file inside a tcsh script. In code:


source $1    
echo $LD_LIBRARY_PATH > temp_file

The expected result: The environment variable set by the script using the source command will be printed into a temporary file.

Actual result: The sourced file runs nicely, but the LD_LIBRARY_PATH variable remains empty.

Any ideas on how to get this to work?

P.S. tcsh is of course not my shell of choice, but I have a script at work that sets up numerous environment variables in tcsh that I want to get working in bash. I figured the easiest way (other than rewriting the tcsh shell every time) is to source it, print out the variables into a file, and with a bit of shell magic, re-source everthing back in bash.

share|improve this question
If you run env before and after source, does anything change? If not, try the same inside the sourced script. That might give some clues. – ams Apr 12 '12 at 11:55
I just tried it; it works for me the way you were expecting. Are you sure your sourced script is setting LD_LIBRARY_PATH? You can add a line at the very end (or anywhere the script might exit) that echos it to a different temp file. – Shawn J. Goff Apr 12 '12 at 12:02
Post the sourced script (preferably shrunk to a small example that exhibits the problem). – Gilles Apr 12 '12 at 23:20

I've tried with csh on OpenBSD. I guess my example works also with tcsh.

File test.csh:

source data.csh

File data.csh

setenv VARIABLE 1234


$ csh test.csh
share|improve this answer
up vote 0 down vote accepted

For further reference, this does indeed work, But one should not use the shebang:


but rather use:

 #!/usr/bin/env tcsh.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.