[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: What is a 'path'?

-- Ben Hartshorne <debian_user@green.hartshorne.net> wrote
(on Wednesday, 04 December 2002, 11:42 AM -0800):
> On Sun, Dec 01, 2002 at 06:54:43PM -0500, sean finney wrote:
> > On Sun, Dec 01, 2002 at 11:36:54PM -0500, alex wrote:
> > > An instruction says:
> > > 
> > > "First, be sure that /usr/X11R6/bin is on your path."
> > > 
> > > What is my "path" and how can I check it?   Is this a matter 
> > > of just editing 'path' and adding /usr/X11R6/bin?
> > > 
> >
> [...]
> > to set your path to include /usr/X11R6/bin, you just need to say
> > 
> > PATH="${PATH}:/usr/X11R6/bin"
> ok, I feel like this is something I should know, but I've never gotten
> it crystal clear.
> PATH=blerg
> export PATH
> When you declare PATH=blerg, the variable PATH is available to the
> current shell.  Under what conditions must you export PATH?  I see it in
> shell initialization scripts, so it has something to do with subshells.
> Does the shell keep separate lists of varibles it knows about and
> variables it passes on to subshells?  why?
> Could someone say exactly what the export PATH part does and under what
> conditions it's necessary?
It depends on the shell you're using. Debian, and most linuces, default
to bash, so that's what I'll address. 

A shell script creates a variable with a declaration like:
    ASTRING="some string"
Such variables are then available elsewhere in the script. Thus, you
could later write:
    exec $PATH/someBinary
and the script will substitute the correct value for $PATH. 

Occasionally, though, your script will want to inform other scripts or
programs about something they've set. They do so via the shell
/environment/, and such variables are then called /environmental
variables/. The method in bash by which this is done is by export-ing
the variable:
    export PATH
(note the lack of a '$' prefix)

Your .bashrc and/or .bash_profile create a bunch of different
environmental variables that are used by other programs. One important
one is $PATH; this defines what directories to look in for executables,
so that you don't need to type the full path (for instance,
/usr/bin/aterm) to execute a program. On Debian, this is initially set to:
where ':' separates different paths.

So, if you need to add another path to your $PATH environment, you can
edit your .bashrc and add the lines:
    export PATH
and '/some/new/path' will be added to the list. If you want it just for
this particular shell in this particular instance, you might type at the
command prompt:
    % export PATH=$PATH:/some/new/path
(where % denotes the prompt)

I have in my own .bashrc:
which tells bash to look in my ~/bin directory for executables /first/
before looking elsewhere on the system.

Most of the time, this shouldn't be necessary; however, if you know an
executable exists, but you cant execute it from the command line, you
may need to futz with your PATH environmental variable... or simply type
the complete path to it (e.g. /usr/local/someprogram/bin/executable).

Hope that clarifies the situation a bit...

Matthew Weier O'Phinney

Reply to: