LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 01-16-2006, 06:27 AM   #1
vivekr
Member
 
Registered: Nov 2005
Location: Coimbatore,India
Distribution: Fedora Core4
Posts: 68

Rep: Reputation: 15
How to set PATH variables


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

Thanks to all
 
Old 01-16-2006, 06:39 AM   #2
zhelezov
Member
 
Registered: Jan 2006
Location: Bulgaria
Distribution: debian, grml, ubuntu
Posts: 69

Rep: Reputation: 15
hi!

Quote:
Also how to view the current PATHs..
Code:
echo $PATH
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.

cheers,
vlado

*this topic must be in...<calc>...n^N howtos

Last edited by zhelezov; 01-16-2006 at 06:47 AM.
 
Old 01-16-2006, 07:40 AM   #3
Dtsazza
Member
 
Registered: Oct 2005
Location: Oxford, UK
Distribution: Debian Etch (w/ dual-boot XP for gaming)
Posts: 282

Rep: Reputation: 31
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.

Last edited by Dtsazza; 01-16-2006 at 07:42 AM.
 
Old 09-02-2011, 12:56 AM   #4
xoy
LQ Newbie
 
Registered: Sep 2011
Posts: 1

Rep: Reputation: Disabled
In Debian like linux configure here:

global for many shells
Code:
/etc/profile
/etc/profile.d/myname.sh
global for bash only
Code:
/etc/bash.bashrc
local for many shells
Code:
~/.profile
local bash only
Code:
~/.bashrc
 
Old 04-02-2012, 11:33 AM   #5
smilemukul
Member
 
Registered: Jun 2009
Distribution: Redhat,CentOS,Ubuntu,Puppet
Posts: 292

Rep: Reputation: 34
Is this possible to modify the env variable as,

export PATH=/home/foo:/bin/ls instead of /bin as I want to define variable path only for /bin/ls ?
 
Old 04-02-2012, 11:47 AM   #6
Sydney
Member
 
Registered: Mar 2012
Distribution: Scientific Linux
Posts: 147

Rep: Reputation: 36
Quote:
Originally Posted by smilemukul View Post
Is this possible to modify the env variable as,

export PATH=/home/foo:/bin/ls instead of /bin as I want to define variable path only for /bin/ls ?
Yes but only for that session. You should check out ~/.bash_profile for editing the path in Bash so it will stick.

~ is a notation for the working user's home directory.

Last edited by Sydney; 04-02-2012 at 11:49 AM. Reason: Added detail.
 
Old 04-02-2012, 06:32 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 18,237

Rep: Reputation: 2711Reputation: 2711Reputation: 2711Reputation: 2711Reputation: 2711Reputation: 2711Reputation: 2711Reputation: 2711Reputation: 2711Reputation: 2711Reputation: 2711
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 ...

Have a read of http://tldp.org/LDP/Bash-Beginners-G...l/chap_03.html
 
1 members found this post helpful.
Old 06-04-2012, 03:39 AM   #8
arijan
LQ Newbie
 
Registered: Dec 2007
Distribution: Debian
Posts: 19

Rep: Reputation: 7
I am a bit confused about $PATH variable. It refers to

/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games,

and if I call $PATH should I have all these paths considered? Or how to refer to particular path within $PATH, like only /usr/bin ?

And another thing:

Can I set variable name in the manner the ~/ is for /home/user ?

Last edited by arijan; 06-04-2012 at 03:51 AM. Reason: Typos
 
Old 06-04-2012, 03:50 AM   #9
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by arijan View Post
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.
 
Old 06-04-2012, 04:03 AM   #10
arijan
LQ Newbie
 
Registered: Dec 2007
Distribution: Debian
Posts: 19

Rep: Reputation: 7
Quote:
Originally Posted by pixellany View Post
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

Last edited by arijan; 06-04-2012 at 04:05 AM.
 
Old 06-04-2012, 07:35 PM   #11
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Code:
[mherring@hering-GTWay ~]$ pwd
/home/mherring
[mherring@hering-GTWay ~]$ export PLAY=/home/mherring/play
[mherring@hering-GTWay play]$ cd /etc/pacman.d
[mherring@hering-GTWay pacman.d]$ cd $PLAY
[mherring@hering-GTWay play]$ pwd
/home/mherring/play
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot set LD_LIBRARY_PATH in .cshrc (able to set other env variables) senthilpr_in Linux - Newbie 4 02-26-2007 12:46 PM
Extra path variables? mjm461 Linux - General 1 09-15-2005 02:21 PM
Set the path systemwide/Set the path for a user with Slackware jayhel Slackware 1 06-12-2005 12:24 AM
How to set PATH and CLASSPATH environment variables bronko Linux - Newbie 2 12-20-2003 11:13 AM
How to set PATH How do I set PATH environment variable? Tranquil Linux - Newbie 3 11-02-2003 02:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration