Section 5.4. Executable Files Versus Built-in Commands


[Page 170 (continued)]

5.4. Executable Files Versus Built-in Commands

Most Linux commands invoke utility programs that are stored in the directory hierarchy. Utilities are stored in files that have execute permission. For example, when you type:

$ ls 



[Page 171]

the shell locates the executable program called "ls," which is typically found in the "/bin" directory, and executes it. The way that the shell finds a utility is described later in this chapter. In addition to its ability to locate and execute utilities, the shell contains several built-in commands, which it recognizes and executes internally. I'll describe two of the most useful ones now: echo and cd.

5.4.1. Displaying Information: echo

The built-in echo command displays its arguments to standard output (Figure 5-4).

Figure 5-4. Description of the echo shell command.

Shell Command: echo {arg}*

echo is a built-in shell command that displays all of its arguments to standard output. By default, it appends a newline to the output.


All of the shells we will see contain this built-in function, but you may also invoke the utility called echo (found in /bin) instead. This is sometimes useful, as some arguments and subtle behavior may vary between the different built-ins and it can be confusing if you write scripts in more than one of these shells. We'll look at writing shell scripts shortly.

5.4.2. Changing Directories: cd

The built-in cd command changes the current working directory of the shell to a new location, and was described fully in Chapter 3, "GNU Utilities for Nonprogrammers."




Linux for Programmers and Users
Linux for Programmers and Users
ISBN: 0131857487
EAN: 2147483647
Year: 2007
Pages: 339

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