Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

#!/bin/tcsh

unsetenv LD_LIBRARY_PATH
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
2  
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
add comment

2 Answers

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

File test.csh:

#!/bin/csh
source data.csh
echo $VARIABLE

File data.csh

#!/bin/csh
setenv VARIABLE 1234

Result:

$ csh test.csh
1234
share|improve this answer
add comment

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

 #!/bin/tcsh 

but rather use:

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

Your Answer

 
discard

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.