next up previous contents
Next: 1.8 File and Directory Up: 1. Basic Linux Commands Previous: 1.6 bash Environment   Contents

1.7 A Few Words About $PATH

One of the most baffling concepts for new users of Linux is the concept of $PATH. $PATH is an environmental variable. Environmental variables can come from many sources, but most are set in the user's .bash_profile. Environmental variables like $PATH tell the shell where to look for executable programs and in genereal how to find things on the system. which shell to use, and other important information about how the user can and will interact with the shell. If a program doesn't exist in the $PATH the shell cannot find, and therefore cannot execute the program. A common question, among new users, is why a command is not executed, even though the user is in the same directory as the binary. The answer is, the shell knows nothing about binaries that are not in the $PATH, unless the full path to the binary is given on the command line. This can be accomplished with several methods. We'll demonstrate two. First give the full path to the executable.

$ pwd

/home/joe

$ /this_directory/that_directory/my_command
The shell will execute my_command, if the user has the proper permissions, because the user has given the shell the full path to the executable.

Or if the command is in the current directory.

$ pwd

/this_directory/that_directory

$ ./my_command
The ``./'' tells the shell to execute my_command in the current directory.

To find out what is in your $PATH do the following.

$ echo $PATH

/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/home/joeuser/bin
The order of the directories in $PATH is significant. It is the order which the shell will search for commands. If there are commands in different directories, with the same name, the first command found will be executed. This is important to know, because it can work against you or you can use it to your advantage.


next up previous contents
Next: 1.8 File and Directory Up: 1. Basic Linux Commands Previous: 1.6 bash Environment   Contents