views:

220

answers:

3

Say I created a linux user account called john. John wants to create a variable called MYVAL with the value Hello World in the linux shell (bash)

MYVAL = 'Hello World'

John does not want to redeclare this variable every time he logs in. Is there some linux config file or start up file that john can declare this variable in such that it will populate every time he starts up his computer?

+4  A: 

This question is better off on serverfault.com, however the answer is yes. You can edit your .bashrc or .bash_profile files in your home directory to set up environment variables at login time.

.bash_profile is the best place for an environment variable like you describe. .bash_profile will be run each time you log in, whereas .bashrc is run each time you open a shell. Slight, but important difference.

zombat
+1  A: 

He can add the variable to the ~/.bashrc file, and this file will be loaded every time he log in.

arsane
Not really. `~/.bashrc` will be loaded only in interactive shells. Usually, `~/.bashrc` will be sourced from within `~/.bash_profile`.
Alan Haggai Alavi
A: 

For the variable to be available everytime the user logs in (login shell) and for every interactive shell, it should be added to ~/.bashrc, and then source ~/.bashrc from within ~/.bash_profile. Bash does not source ~/.bashrc when invoked as a login shell. For interactive shells, Bash does not source ~/.bash_profile.

Alan Haggai Alavi