You are not logged in.

#1 2011-09-11 04:26:08

Padfoot
Member
Registered: 2010-09-03
Posts: 381

[SOLVED] Problem adding a path to environment variable

Hi,

Hoping someone can help.

I am trying to add a path to $XDG_DATA_HOME on login.

After googling and following examples, I have tried the following without success:

export XDG_DATA_HOME=$XDG_DATA_HOME:/path/to/add

I have tried adding the above to ~/.bash_profile, does not work.
I have also tried placing a script (and making it executable) in /etc/profile.d with the same code, does not work.
I have even created a local script and added to my startup applications, does not work.

(I have confirmed the local script is definitely run without error.)

Yet by simply entering the code into a terminal, it works.

Help!

Cheers.

[CORRECTION] Just a correction for those looking to do the same, the ~/.profile solution below works a treat. I just need to point out that you should use XDG_DATA_DIRS instead of XDG_DATA_HOME. Looking at the Freedesktop spec for base directories, XDG_DATA_HOME is treated as a single directory, thus any additions you make to it will change your settings directory causing many problems. The same goes for XDG_CONFIG_HOME, use XDG_CONFIG_DIRS instead![/CORRECTION]

Last edited by Padfoot (2011-09-12 07:52:51)

Offline

#2 2011-09-11 06:14:31

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,324

Re: [SOLVED] Problem adding a path to environment variable

I have also tried placing a script (and making it executable) in /etc/profile.d with the same code, does not work.
I have even created a local script and added to my startup applications, does not work.

When the scripts terminate, the new variables go out of scope and are destroyed.

I have tried adding the above to ~/.bash_profile, does not work. 

hmm  I think that should work.  What if you put it in ~/.bashrc instead.  Also, check the permissions and ownership of ~/bash_profile.  Ensure you own it and it is executable.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#3 2011-09-11 06:34:51

Padfoot
Member
Registered: 2010-09-03
Posts: 381

Re: [SOLVED] Problem adding a path to environment variable

Thanks for the heads up on the scripts.

~/.bash_profile has me annoyed though. It's as if it is not being executed. Will have to try adding something with a visible effect to confirm.

My ~/.bash_profile is owned by me and is executable but it simply will not add the path to the variable.

Could it be something to do with the way my session is handled?

I am currently launching my session through GDM via inittab. I know when a session is launched this way, for example, ~/.xinitrc is ignored. Perhaps this is the same for ~/.bash_profile?

Regarding ~/.bashrc, it does work this way, but it only adds the path when a terminal is launched. I need the path added regardless of a terminal being opened or not.

Cheers.

Offline

#4 2011-09-11 06:53:19

Padfoot
Member
Registered: 2010-09-03
Posts: 381

Re: [SOLVED] Problem adding a path to environment variable

Confirmed, ~/.bash_profile is not being executed at all.

Offline

#5 2011-09-11 08:39:35

moetunes
Member
From: A comfortable couch
Registered: 2010-10-09
Posts: 1,033

Re: [SOLVED] Problem adding a path to environment variable

Padfoot wrote:

Confirmed, ~/.bash_profile is not being executed at all.

Sounds like starting gdm from inittab hasn't set the environment up for you right.
what does

echo $SHELL

and

echo $PATH

return?


You're just jealous because the voices only talk to me.

Offline

#6 2011-09-11 08:40:00

lunar
Member
Registered: 2010-10-04
Posts: 95

Re: [SOLVED] Problem adding a path to environment variable

Did you try "~/.profile"?

Btw, "~/.bash_profile" doesn't need to be executable.

Offline

#7 2011-09-11 14:19:42

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: [SOLVED] Problem adding a path to environment variable

~/.bash_profile is only read when bash is started as a login shell. There's an enormous section in bash(1) called INVOCATION that describes startup behavior, including what files are read, and when.

Last edited by falconindy (2011-09-11 14:20:09)

Offline

#8 2011-09-12 07:12:21

Padfoot
Member
Registered: 2010-09-03
Posts: 381

Re: [SOLVED] Problem adding a path to environment variable

@moetunes

$ echo $SHELL
/bin/bash
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/java/jre/bin:/usr/bin/vendor_perl:/usr/bin/core_perl

Looks like my environment is set up correctly.

@falconindy
Thanks for pointing that out. I was not aware bash had to be started as a login shell in this case. Normally I take great care with RTFM, but usually have a total memory lapse when it comes to man smile

@lunar
~/.profile is the solution. Thank you.

Problem solved. Thank you everyone for all your help.

Cheers.

Offline

Board footer

Powered by FluxBB