Wednesday, March 31, 2010

how to set variables in Linux ubuntu...???

Question: I wrote my own shell scripts and kept those in bin directory in my home directory. I set the PATH variable as PATH=$PATH:$HOME/bin so that i can run those scripts directly as usual commands whatever may be the present working directory. But it is working for that session only. If I close the shell prompt and reopen it, the previous PATH variable that i set is dissapearing from PATH. Now, the scripts which are in bin directory, can no more run as usual commands. I need to again set the PATH variable to that bin directory.
Is there any way to set environmental variable "PATH" permanantly so that it will not dissappear from PATH variable listing?

Answer: Assuming you are using bash as your shell, put this in your .bashrc file. Your .bashrc file should be located in /home/Yourusername/.bashrc or ~/.bashrc for short.

this is what you should put in that file:

export PATH=$PATH:/home/YourUserName/bin

OR

If you want to set the path of a user you can edit your .bash_profile in home directory.

In my .bash_profile i have:

# set PATH so it includes user's private bin if it exists
if [ -d ~/bin ] ; then
PATH=~/bin:"${PATH}"
fi

If you don't have it copy and paste this code.


No comments: