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'd like to set a couple of environment variables (at boot time) on an Ubuntu machine (10.04), but I want to create their value via a script, much like:

export THE_ENV_VAR=$(script_to_execute_and_use_stdout_from)
  • The reason I want to do this is that the commands used to set the environment variables take long time to execute (10s or so), so that's why I only want to do it once after boot. Anyway, currently I solved this by caching the result of the command at boot time, so that subsequent calls will go fast, thus not using env. variables at all.

I've tried setting in /etc/environment, but that only copies rhs verbatim

I've tried executing a script in /etc/init.d/ at startup, but that does not seem to work.

Ideas?

share|improve this question

2 Answers 2

Put that in ~/.bash_profile or ~/.bashrc

gedit ~/.bashrc

Use .bash_profile if you need to use those variable with non-interactive shells (scripts) and ~/.bashrc if you are setting your variables in a shell.

If that does not work, we need more details, in particular what variables are you setting and for what purpose ?

share|improve this answer
    
This is not at boot time... –  user877329 Oct 22 at 9:53

Put your commands into /etc/rc.local. Make sure to read the comments at the head.

share|improve this answer
    
Ok, tried that too, but it doesn't seem to work either, when I login after rebooting the variables don't exist :( –  Robert Oct 13 '11 at 4:31

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.