0

i am doing a python-django project, And what i want to do is, i want to set

variables like password,db_name etc as an environment variable. And i want

to access it as os.environ["db_name"]

i tried like this

inside /home/thameem/Django_projects/lotus/env_var

export db_name="thameem"

inside /etc/environment file

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"


PATH="$PATH:/home/thameem/Django_projects/lotus/env_var" 

and in terminal i tried :

echo $db_name 

but it does not shows the value of db_name

if the question is not correct, somebody please correct the question

i checked this one :: How do I add environment variables?

Thameem
  • 101

1 Answers1

3

If you want to keep the assignments in a separate env_var file, you would need to source it from one of your shell's startup files, rather than adding it to your PATH

For example, you could add something like

if [ -r "$HOME/Django_projects/lotus/env_var" ]; then
  . "$HOME/Django_projects/lotus/env_var"
fi

to the bottom of your ~/.profile

I don't recommend adding it to a system-wide file such as /etc/profile since the file is in your home directory.

steeldriver
  • 136,215
  • 21
  • 243
  • 336
  • thanks for your answer. i copied your code inside the .profile file and open a new terminal and i entered the echo $db_name. But it not shows the value of db_name. it shows blank. – Thameem Sep 25 '16 at 15:17
  • It will be set next time you log in - or you can open a new login shell in your current session either explicitly (using bash -l) or implicitly (e.g. su - thameem) – steeldriver Sep 25 '16 at 15:28