LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 05-29-2012, 03:26 PM   #1
d.spitler
LQ Newbie
 
Registered: May 2012
Posts: 2

Rep: Reputation: Disabled
What is the purpose of the PATH variable?


What is the purpose of the PATH variable?
 
Old 05-29-2012, 03:32 PM   #2
Taylrl
Member
 
Registered: Jul 2010
Distribution: Ubuntu
Posts: 34

Rep: Reputation: 0
I'm more or less a total newbie myself but I am trying to use one so that I can run an executable from anywhere, a bit like how you might use gcc to compile something.

I am sure someone else can give a better, more thorough explanation though :-)
 
Old 05-29-2012, 03:40 PM   #3
towheedm
Member
 
Registered: Sep 2011
Location: Trinidad & Tobago
Distribution: Debian Stretch
Posts: 612

Rep: Reputation: 125Reputation: 125
When you issue a command to run an application, the system sequentially searches the directories specified in the PATH variable.

For example: If your PATH var contains '/usr/bin:/usr/local/bin:/bin and issue the command to run the test.sh script, the system would look for the test.sh script first in /usr/bin, then /usr/local/bin and finally /bin.

If runs the first instance of the file found. If after searching the directories specified in your PATH var, it does not find a test.sh file it issues the 'command not found' error message.

However, if your specify an absolute path for test.sh, it ignores all of the above and looks directly in the directory specified for the file. So entering:
Code:
/usr/bin/test.sh
would cause the system to look directly in /usr/bin for the test.sh file.

To run the test.sh script from the present working directory, use:
Code:
./test.sh

Last edited by towheedm; 05-29-2012 at 04:27 PM. Reason: Corrected errors as pointed out by 273.
 
Old 05-29-2012, 04:03 PM   #4
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Quote:
Originally Posted by towheedm View Post
When you issue a command to run an application, the system searches the present working directory for the app. If it is not found there, it then sequentially searches the directories specified in the PATH variable.

For example: If you are in your home directory ... the system would look for the test.sh script in your home directory.
Unless you have made some modifications to your system then this is not true under Linux/Unix. The current directory is not searched, often leading to confusion for people new to Linux/Unix.
 
Old 05-29-2012, 04:15 PM   #5
towheedm
Member
 
Registered: Sep 2011
Location: Trinidad & Tobago
Distribution: Debian Stretch
Posts: 612

Rep: Reputation: 125Reputation: 125
My mistake, you're correct. Not on my p's and q's.
 
Old 06-06-2012, 08:16 AM   #6
d.spitler
LQ Newbie
 
Registered: May 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thank you for your responses that helps!!!
 
  


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
[SOLVED] What is the purpose of the DISPLAY environment variable? anidev Linux - General 11 11-16-2010 08:06 PM
Add path to $PATH variable alaios SUSE / openSUSE 2 04-19-2009 09:41 AM
bash script path issue - how to pass a path as a string to a variable PiNPOiNT Programming 5 04-17-2009 06:48 PM
Path Variable answerme Linux - Newbie 6 04-19-2008 03:35 AM
$path variable ? moby Linux - Newbie 3 06-01-2004 04:18 PM

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

All times are GMT -5. The time now is 06: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