LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-22-2007, 12:27 PM   #1
linux_2007_
Member
 
Registered: Feb 2007
Posts: 80

Rep: Reputation: 15
Path


SPATH shows all the paths that any executable file in there can be run from any directory. If correct, how can I add a new path (directory) to the list? There must be a file somewhere, I just don't remember where was it?

And, how can I add the current directory (.) so that every time I do not have to type ./ ?

Thanks!

.
 
Old 03-22-2007, 12:37 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
add a line like

path=$path:/my/new/dir

to a file like ~/.bash_profile for yourself, or /etc/profile for system wide change.

as for ./, don't. it's a very common newbie urge, but really... don't.
 
Old 03-22-2007, 12:40 PM   #3
MOS JEFF-INITELY
Member
 
Registered: Sep 2006
Distribution: Windows .. MUAHAHAHA
Posts: 66

Rep: Reputation: 15
add this to your .profile
export PATH=.:$PATH

this way it will check the directory your in first and will set your $PATH every time you log in.

to add another path do a similar thing:

export PATH=$PATH:newpath1:newpath2

the semi-colon is the delimeter to clarify when a new path starts and ends. You can also run this from command line to set for your current shell environment however this will be reset when you open a new shell.
 
Old 03-22-2007, 01:11 PM   #4
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
$PATH not SPATH.

The variable name is PATH. You tell the shell it is a variable by prepending it with the $ so it becomes $PATH.

To add items to existing PATH:

PATH=$PATH:/new/path/dir

This puts /new/path/dir into your PATH after whatever was already there. The colon ( is the separator it uses.

You can see value of PATH by typing:
echo $PATH

PATH is typically started within your /etc/profile or /etc/bashrc. You could see multiple lines adding to it there. It is then added to by your user's $HOME/.profile, $HOME/.bashrc and/or $HOME/.bash_profile.

Typically you'd want to edit the file in $HOME as that affects. ($HOME by the way is another variable = your home directory).
 
Old 03-22-2007, 02:39 PM   #5
linux_2007_
Member
 
Registered: Feb 2007
Posts: 80

Original Poster
Rep: Reputation: 15
Sorry about SPATH, just mistyping.

echo $PATH shows about 10 different paths on my machine, but they are not in /etc/profile, nor /etc/bash.bashhrc (I don't have /etc/bashrc). As a matter of fact, these 2 files are more like a program with lots of "if" command.

So, these specified paths have to be somewhere else. Any idea?

.
 
Old 03-22-2007, 02:46 PM   #6
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
You didn't mention the files in $HOME of which I spoke.

When you login depending on shell it FIRST loads in /etc/profile or /etc/bashrc THEN loads in whatever is in the $HOME of the user that logged in.

Also if any of those files invoked other files then it would load in variables specified in that. An example is that some people have $HOME/.bash_profile invoke $HOME/.bashrc. In that case it would load:
/etc/bashrc
$HOME/.bash_profile
$HOME/.bashrc

It can also load in files we don't know about e.g. /usr/local/bin/somescript.sh (not a real name - just an example).
That script could also be loading in other files we don't know about.

Look at $HOME for the appropriate user. Notice "." in the names above - that is a "hidden" file so doesn't show up with "ls -l" - you have to do "ls -la".
 
Old 03-24-2007, 01:52 PM   #7
linux_2007_
Member
 
Registered: Feb 2007
Posts: 80

Original Poster
Rep: Reputation: 15
Thanks for all the information. By "echo $HOME", I get a list of a number of files, including those ones starting with ".", such as .profile and .bashrc. I opened them both, but I still don't see the directories which are listed by "echo $PATH". They must be somewhere, and the reasonable place is either .profile (or /etc/profile) or .bashrc (or /etc/bashrc; as I said before I don't have /etc/bashrc, but I do have /etc/bash.bashrc).

Any idea how the specified PATHs are working on my machine?

By the way, in /usr/local/bin/ , I don't see any file with "sh" extension (ie, *.sh).

.
 
Old 03-24-2007, 02:11 PM   #8
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Quote:
Originally Posted by MOS JEFF-INITELY
add this to your .profile
export PATH=.:$PATH

this way it will check the directory your in first and will set your $PATH every time you log in.
Again, i've got to say this is really really nasty practise. a command should run from anywhere when an absolute or relative path is not specified. running "mycommand" in your home directory may run /home/user/mycommand but running it whilst in /tmp may fall back to /usr/bin/mycommand. this is really really nasty...
 
Old 03-24-2007, 05:44 PM   #9
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
You just don't seem to be getting it.

I'd suggest you read the man pages for "login" and "bash".

When you login you invoke a file in /etc first (which one it is depends on your shell)). THAT file may contain directives to "source" other files which could be named ANYTHING. The sourced files may in turn invoke files named ANYTHING. After the /etc (which is "global" meaning all users get them) it then goes to the files in $HOME of the specific user to invoke "local" files. These files can also source in other files which could be named anything. The sourced in files can also source in other files and so on.

You have to look at everything that is occurring when you login. There is no way anyone else can tell you what you are getting for PATH without knowing all the files you're invoking/sourcing and they are not the same on every system.

I once had a system where /etc/profile was fairly simple but .profile in $HOME invoked a script which in turn invoked another script which sourced in a specialized profile which invoked yet another script. Either you're not reading your files correctly or they're doing something similar to this because someone else set them up for you. If the latter you might want to ask that person.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Do you add to the path line or make a new path in /etc/profile? M$ISBS Linux - Newbie 2 12-13-2006 02:14 PM
Image Path reference in Linux (Absolute path) javabuddy Linux - General 7 06-05-2006 07:45 AM
script to change unix path to windows path in all files csross Programming 8 04-29-2006 01:05 PM
Why is the value of $PATH in console mode different from the $PATH in xterm emulator? Akhran Debian 9 03-09-2006 06:10 PM
How to Chnage Python's module search path (sys.path)? lramos85 Linux - Software 1 05-02-2004 06:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:51 PM.

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