Built-in Programs and External Programs

Two different types of command can be executed from a shell. They are built-in programs and external programs :

  • Built-in programs are inherently built into the shell:

    • All shells share a common set of built-in programs, such as the cd command, which enables you to change directory.

    • In addition, there are other built-in commands that are specific to certain flavors of the shell. For example, the amend method for setting environment variables usually varies from one flavor of the shell to another (more on setting environment variables later in this chapter).

  • External commands are those that are independent of the flavor of shell. They can be executed from any shell and yield more or less the same result. For example, the date command would output the date no matter what shell it is executed from.

For the purpose of our discussion, we shall refer to both built-in commands and external commands by the generic term , command .

Of course, when you re working within a particular shell, you can use only the built-in commands that are valid for that flavor of shell. As you ll see in the Shell Scripting section towards the end of this chapter, this is particularly important when you write a shell script, a file that contains a sequence of shell commands. If you run a shell script within a particular shell, it should contain only commands that are valid for the shell in question.

To this end, it is useful to be able to check whether a given command is a built-in or an external command. For this, you can use the type command. This command tells you whether it is a built-in command within the current shell, or (if it is an external program) the location of the command.

For example, in the Bash shell, if you use type to query the nature of the date and cd commands, you ll find that the former is external and the latter is built-in:

   $ type date   date is /bin/date   $ type cd   cd is a shell builtin 

Shell scripts are discussed in detail in the Shell Scripting section of this chapter.

Beginning Fedora 2
Beginning Fedora 2
ISBN: 0764569961
EAN: 2147483647
Year: 2006
Pages: 170

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net