I need to have a variable $FOO on the system that contains a string all users could use, but I have no idea how to create one.

The Upstart job is obviously not a solution as from this thread - Is it possible to export env variable via Upstart?

But I have no idea where else I should look, being Windows developer for a very long time.


Adding to the answers already given, other places to set the variable would be:

  • a file under /etc/env.d (shell-independent),
  • /etc/bash/bashrc for bash users,
  • /etc/zshenv or /etc/zprofile or /etc/zshrc or /etc/zlogin for zsh (as per man zsh),
  • other shell-specific config files, described in each shell's manpage under FILES section.
  • They all are manual entries, but I somehow need to change it per reboot programmatically... :( Should I add a variable in `FOO=``expression to eval``` – Coder Sep 16 '11 at 11:19
  • Yes, you can use something like FOO="$(some command)". But maybe you could just describe what you need exactly - there may be a method that you overlooked and all the struggle with variables is unnecessary (or can be simplified). – rozcietrzewiacz Sep 16 '11 at 11:36
  • There is a shell script that has a variable with a location to network machine. But upon bootup I need to change the IP in that script, because IP of target machine can change. I can query it via script though, but it would be great if I could do that just once, while booting. – Coder Sep 16 '11 at 11:52
  • OK! This is something that doesn't need any environmental variable being set, just an entry in /etc/hosts which you might modify at startup. – rozcietrzewiacz Sep 16 '11 at 13:53

Many distributions use /etc/environment for this purpose. There is some information about it on the Ubuntu Wiki and the Arch Wiki, among others.


If /etc/environment doesn't exist, then you could use either/etc/profile or /etc/profile.d/FOO to set up your environment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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