pavement

PATH

From FreeBSDwiki
(Difference between revisions)
Jump to: navigation, search
m (Reverted edits by 220.2.200.254 (Talk); changed back to last version by Dave)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
PATH in unix is the same as in DOS; the directories that your shell/command line interface checks for commands in. This can be set to a default in your [[skeleton_file]] or it can be set in your [[shell]] [[.profile]] or you can set it from the command line itself. You'll need to run the command ''set PATH'' and export the PATH; doing it this way means that you will not save your new path -- it'll be lost once you log out or reboot the machine.
+
PATH is a system variable which functions in unix much the same as it does in DOS; it contains the directories that your shell/command line interface checks for commands in. This can be set to a default in your [[skeleton_file]] or it can be set in your [[shell]] [[.profile]] or you can set it from the command line itself. You'll need to run the command ''set PATH'' and export the PATH; doing it this way means that you will not save your new path -- it'll be lost once you log out or reboot the machine. You can see your current PATH by asking the shell to [[echo]] it:
 +
 
 +
'''samizdata#''' echo $PATH
 +
/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin:/root/bin
 +
'''samizdata#''' logout
 +
'''dave@samizdata:~%''' echo $PATH
 +
/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin:/home/dave/bin
 +
'''dave@samizdata:~%'''
 +
 
 +
There are, however, a couple of significant differences between the way PATH is utilized under DOSlike and Unixlike systems.  First, DOSlikes always silently include '''./''' (the current directory) as part of the PATH, whereas Unixlikes do not (and should not, for security reasons).  This means that on a DOSlike system, if you are in the same directory as program.exe, you can run it simply by typing '''program.exe'''.  On a unixlike system, you would need to instead type in '''./program.exe''' to specify the current directory directly.
 +
 
 +
Another significant difference is that under a DOSlike system, the PATH is interpreted fresh every time it's called - meaning that if you drop a new program into your PATH somewhere, you can immediately call it from anywhere on the system without specifying a path to it.  While this is convenient, it does mean that it takes longer to execute any pathless command the longer the PATH becomes, and also makes it somewhat easier to get an unsuspecting user to unwittingly run a trojan horse.  So Unixlike systems do it a little differently - under a Unixlike system, the PATH is read, and all programs within it have their pathnames cached at the startup of a shell session.  To manually re-interpret the PATH so that new programs can be found, you need to use the [[rehash]] command if you're on a [[csh]] or [[ksh]]-based shell or use [[source]] to your [[.bashrc]] file if you're using a [[bash]]-based shell.
 +
 
 +
[[Category:System Commands]]
 +
 
 +
[[Category : New_User_Tips_and_FAQs]]

Latest revision as of 13:26, 5 May 2007

PATH is a system variable which functions in unix much the same as it does in DOS; it contains the directories that your shell/command line interface checks for commands in. This can be set to a default in your skeleton_file or it can be set in your shell .profile or you can set it from the command line itself. You'll need to run the command set PATH and export the PATH; doing it this way means that you will not save your new path -- it'll be lost once you log out or reboot the machine. You can see your current PATH by asking the shell to echo it:

samizdata# echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin:/root/bin
samizdata# logout
dave@samizdata:~% echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin:/home/dave/bin
dave@samizdata:~%

There are, however, a couple of significant differences between the way PATH is utilized under DOSlike and Unixlike systems. First, DOSlikes always silently include ./ (the current directory) as part of the PATH, whereas Unixlikes do not (and should not, for security reasons). This means that on a DOSlike system, if you are in the same directory as program.exe, you can run it simply by typing program.exe. On a unixlike system, you would need to instead type in ./program.exe to specify the current directory directly.

Another significant difference is that under a DOSlike system, the PATH is interpreted fresh every time it's called - meaning that if you drop a new program into your PATH somewhere, you can immediately call it from anywhere on the system without specifying a path to it. While this is convenient, it does mean that it takes longer to execute any pathless command the longer the PATH becomes, and also makes it somewhat easier to get an unsuspecting user to unwittingly run a trojan horse. So Unixlike systems do it a little differently - under a Unixlike system, the PATH is read, and all programs within it have their pathnames cached at the startup of a shell session. To manually re-interpret the PATH so that new programs can be found, you need to use the rehash command if you're on a csh or ksh-based shell or use source to your .bashrc file if you're using a bash-based shell.

Personal tools