954,234 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how can i set my own environment variables in linux?

Hi
Ok guys I'm trying to make my own environment variables but it's not working , please help me with this .
Also please don't give me a link to something you got by googling , because i can search it myself but i need some simple explanation .

alaa sam
Junior Poster
135 posts since Nov 2010
Reputation Points: 8
Solved Threads: 10
 

What have you tried?

shibblez
Junior Poster in Training
72 posts since Oct 2010
Reputation Points: 15
Solved Threads: 6
 

set CDIR=/media/Alaa

alaa sam
Junior Poster
135 posts since Nov 2010
Reputation Points: 8
Solved Threads: 10
 

You then need to export it if it is going to be user in a child process. It would be easier if you were to post more of the script than just the single line.

shibblez
Junior Poster in Training
72 posts since Oct 2010
Reputation Points: 15
Solved Threads: 6
 

ok , i didn't get any thing by the way I'm just a beginner , can you explain more

alaa sam
Junior Poster
135 posts since Nov 2010
Reputation Points: 8
Solved Threads: 10
 

Hi alaa sam,
The two ways of setting the environment variables are:
1. "name of your env variable"="path to command". For example, let's say you want to access a folder named alaa located on your desktop from anywhere in your directory path, say from /etc/sam , you can set an environment variable as such alaa=$HOME/Desktop/alaa . So when you are in any directory, to access the folder alaa, all you'd have to do is type cd $alaa. The downfall with this method is that it's temporary in that it will only apply for the current shell you're in. If you open a new shell, the variable won't apply

2. The second method is a bit permanent(in terms of shell persistence) and it involves the use of export. Using the same example as above, you'd type export alaa=$HOME/Desktop/alaa . The results would be the same as above except this time, all shells you open would be able to access the variable. However, in both instances, if you log out completely, the variables you've set would not be available for the next session you log in. To make the changes permanent, you'd need to edit your .profile file by adding the new command(s) to it.

c-tech
Junior Poster
119 posts since Aug 2007
Reputation Points: 13
Solved Threads: 8
 

If I want them permanent what shoul I add to .profile
????

alaa sam
Junior Poster
135 posts since Nov 2010
Reputation Points: 8
Solved Threads: 10
 

You'll need to find your user profile which is usually under /etc/your_user_login_name/.bash_profile. N.B, you should replace the text in italics with your username on the system. To add the command, just type :absolute path to your command immediately after the line starting with PATH. Save the changes and exit. In the terminal, type export $PATH. The new command alaa should now be accessible even after rebooting.

c-tech
Junior Poster
119 posts since Aug 2007
Reputation Points: 13
Solved Threads: 8
 

thanks a lot

alaa sam
Junior Poster
135 posts since Nov 2010
Reputation Points: 8
Solved Threads: 10
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: