Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm running Ubuntu 12.04

I added

export LD_LIBRARY_PATH=/home/dspies/workspace/hdf5-1.8.11-linux-shared/lib

to .profile

but when I log in and open terminal and put echo $LD_LIBRARY_PATH there's nothing.

When I switch to ctrl-alt-F1 and log in, echo $LD_LIBRARY_PATH gives

/home/dspies/workspace/hdf5-1.8.11-linux-shared/lib

but then when I run screen, echo $LD_LIBRARY_PATH from within screen is empty again

In what circumstances can I expect environment variables from .profile to be set? (interestingly, it seems any modifications to PATH made in .profile always show up)

EDIT: Sorry, I guess I didn't clarify what I really wanted to know which is: How can I set an environment variable that I mean to be set anywhere (ie in screen, in terminal, when I log-in, and when I ssh in)?

share|improve this question
    
What is the output of echo $0? –  thefourtheye May 22 '13 at 7:36
    
From within terminal, it's just "bash", in CTRL-ALT-F1, it's "-bash", and in screen, it's "/bin/bash". Why? What is $0? –  dspyz May 22 '13 at 7:40
add comment

3 Answers 3

From the Bash manual:

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.

That means if you have a .bash_profile or .bash_login in your home folder, then bash won't read the contents of your .profile. Additionally, when not running in an interactive login shell, .profile won't be read either.

share|improve this answer
add comment
echo $0

will return the script name which is being executed, when this command is executed within a shell script. In a terminal, it will return the type of shell being used.

You are using bash shell. You need to add this line

export LD_LIBRARY_PATH=/home/dspies/workspace/hdf5-1.8.11-linux-shared/lib

to ~/.bash_profile file.

EDIT:

You may find the different login profile scipt names for different shells, here

EDIT2:

Even I got two different responses when I executed echo $0 on two different machines. On one machine, I got bash and on the other I got -bash. I asked that question here. This is what I got as the answer.

Processes with a - at the beginning of arg 0 have been run via login, or by exec -l in bash.

After reading that answer, I did help exec and that reads, If the first argument is '-l', then place a dash in the zeroth arg passed to FILE, as login does.

share|improve this answer
add comment
up vote 1 down vote accepted

The answer is:

I should set them in .pam_enviornment

See here https://help.ubuntu.com/community/EnvironmentVariables

I imagine this is one of the most common questions, I don't know why nobody gave me the proper answer when I asked this question.

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.