Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
This may be a terribly easy question but being a newbie to the whole Linux stuff... I dont have any other option than asking it openly and accepting frankly my ignorance..
So how to set environment variables in Linux.
I think I have to use set PATH variable..
But I am dont want to take risk..
Also unlike Windows there seems to be many paths...
Will export pathname=PATH1;PATH2; suffice?
Also how to view the current PATHs..
All info regarding environmental variable setiing and manipulating are welcome
i prefer storing my custom variables and aliases in a separate file rather than in ~/.bashrc (is bash your login shell?) like ~/.yourvar which is executed upon login. to get this done add this line to ~/.bashrc
Code:
source ~/.yourvar
Quote:
Will export pathname=PATH1;PATH2; suffice?
export like this in your ~/.yourvar or ~/.bashrc ...as you like:
Code:
export PATH=$PATH:/dir1:...:/dirN
as many directories as you need.
thus you'll have N directories ADDED to your PATH variable. easy, isn't it.
Distribution: Debian Etch (w/ dual-boot XP for gaming)
Posts: 282
Rep:
Since you asked about environment variable manipulation in general, I found the set command very useful when I first came across it - it simply prints (to standard out) a list of all the currently active environment variables. Useful for double-checking you've sorted things properly - though I have a feeling it might only work for bash.
And to expand on zhelezov's method to set paths, you can execute that command from a shell, though it will remain active only in that shell and only until the shell is closed (e.g. if you started an xterm, set some variables, closed xterm and then opened xterm again, it'd be a new shell and your custom variables wouldn't be set). Also, the "$PATH:" at the front is not technically necessary (though a good idea) - what it does is substitute your current PATH variable at the start of the right hand side, so dir1,... dirN get added onto the end of your existing path. If you want to explicitly set path to "/home/foo" and nothing else, then
Code:
export PATH=/home/foo
will do exactly that. Of course, in the vast majority of cases, you'll simply want to add another directory onto your existing path, so using the "$PATH:" format is preferable.
As above, there are many environment variables used for many reasons; to see them try the cmds
Code:
set
env
PATH is just one of many default variables and you can create your own.
Use the above techniques in login files to ensure new definitions are re-created when you login again.
Note that you need the export cmd to push the declarations down to sub-shells, otherwise they only affect current shell.
You cannot push them up the shell tree though ...
I am not sure if this question is set properly, but here it is:
I was wondering how can I create a path that is a reference to full path - like ~/ for /home/user ?
For instance, I would like to have /media/trans500/dl/music referenced by something shorter, something that I can easily type without using clipboard all the time.
Thanks
Just make a soft link.....For example, in your home directory, enter this:
Code:
ln -s /media/trans500/dl/music music
then, to go to that directory, just type "music"
To relate this to the original topic (the PATH env variable), the latter is intended to establish the search path for commands.
Just make a soft link.....For example, in your home directory, enter this:
Code:
ln -s /media/trans500/dl/music music
then, to go to that directory, just type "music"
To relate this to the original topic (the PATH env variable), the latter is intended to establish the search path for commands.
Thanks!
I apologize for editing my question - I wanted to put it in a different shape...
Ok, the ln is a way around. If I want to put a path to my music folder into let's say playlist conf file. I would than have to write ~/music.
But if I want to have clean path to /media/trans500/dl/music as just music, than ln desn't help. I was wondering if a global variable that refers to this path could be given by setenv and used in conf files or from wherever, like: MUSIC= /media/trans500/dl/music
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.