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 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.

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

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.
share|improve this answer
    
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
add comment

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

share|improve this answer
add comment

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

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.