
7 – Seeing The World As The Shell Sees It
7 – Seeing The World As The Shell Sees It
In this chapter we are going to look at some of the “magic” that occurs on the command
line when you press the enter key. While we will examine several interesting and com-
plex features of the shell, we will do it with just one new command:
● echo – Display a line of text
Expansion
Each time you type a command line and press the enter key, bash performs several pro-
cesses upon the text before it carries out your command. We have seen a couple of cases
of how a simple character sequence, for example “*”, can have a lot of meaning to the
shell. The process that makes this happen is called expansion. With expansion, you enter
something and it is expanded into something else before the shell acts upon it. To demon-
strate what we mean by this, let's take a look at the echo command. echo is a shell
builtin that performs a very simple task. It prints out its text arguments on standard out-
put:
[me@linuxbox ~]$ echo this is a test
this is a test
That's pretty straightforward. Any argument passed to echo gets displayed. Let's try an-
other example:
[me@linuxbox ~]$ echo *
Desktop Documents ls-output.txt Music Pictures Public Templates
Videos
So what just happened? Why didn't echo print “*”? As you recall from our work with
wildcards, the “*” character means match any characters in a filename, but what we didn't
see in our original discussion was how the shell does that. The simple answer is that the
shell expands the “*” into something else (in this instance, the names of the files in the
67