That would take a long time. We see that we don't usually have to specify a complete path name to the program we want to run, the shell just seems to know. Well, that's correct. The shell does know. Here's how: the shell maintains a list of directories where executable files programs are kept, and only searches the directories on that list.
If it does not find the program after searching each directory on the list, it will issue the famous command not found error message. This list of directories is called our path. We can view the list of directories with the following command:. This will return a colon separated list of directories that will be searched if a specific path name is not given when a command is entered. In our first attempt to execute our new script, we specified a pathname ".
We can add directories to our path with the following command, where directory is the name of the directory we want to add:. A better way would be to edit our. That way, it would be done automatically every time we log in. This directory is called bin and is a subdirectory of our home directory.
If we do not already have one, we can create it with the following command:. If we move our script into our new bin directory we'll be all set. Now we just have to type:. On some distributions, most notably Ubuntu and other Debian-based distributions , we will need to open a new terminal session before our newly created bin directory will be recognized. Shotts, Jr. Verbatim copying and distribution of this entire article is permitted in any medium, provided this copyright notice is preserved.
Name Description Interface vi, vim The granddaddy of Unix text editors, vi , is infamous for its obtuse user interface. On the bright side, vi is powerful, lightweight, and fast. Learning vi is a Unix rite of passage, since it is universally available on Unix-like systems. On most Linux distributions, an enhanced version of vi called vim is provided in place of vi.
Emacs contains or can be made to contain every feature ever conceived of for a text editor. It should be noted that vi and Emacs fans fight bitter religious wars over which is better. In the simplest terms, a shell script is a file containing a series of commands. The shell reads this file and carries out the commands as though they have been entered directly on the command line.
The shell is somewhat unique, in that it is both a powerful command line interface to the system and a scripting language interpreter. As we will see, most of the things that can be done on the command line can be done in scripts, and most of the things that can be done in scripts can be done on the command line.
We have already covered many shell features, but we have focused on those features most often used directly on the command line. The shell also provides a set of features usually but not always used when writing programs.