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 .

Recommended Answers

All 8 Replies

What have you tried?

set CDIR=/media/Alaa

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.

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

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.

commented: Great explanation. +7

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

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.

thanks a lot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.