Previous | Table of Contents | Next |
Hour
My father has a tool chest that holds all his woodworking tools, from screwdrivers and chisels to power sanders and power drills. He has used these tools to build several desks, a shed, a bridge, and many toys. By applying the same tools, he has been able to build all the different elements required for his projects.
Shell scripting is similar to a woodworking project. To build something out of wood, you need to use the right tools. In UNIX, the tools you use are called utilities or commands. There are simple commands like ls and cd, and there are power tools like awk, sed, and the shell.
One of the biggest problems in woodworking is using the wrong tool or technique while building a project. Knowing which tool to use comes from experience. In this book, you will learn how to use the UNIX tools via examples and exercises.
The simple tools are easy to learn. You probably already know how to use many of them. The power tools take longer to learn, but when you get the hang of them, youll be able to tackle any problem. This book teaches you how to use both the simple tools and the power tools. The main focus is on the most powerful tool in UNIX, the shell.
Before you can build things using the shell, you need to learn some basics. This chapter looks at the following topics:
Its time to get started.
In UNIX, a command is a program that you can run. In other operating systems, such as Mac OS or Windows, you point to the program you want to run and click it. To run a command in UNIX, you type its name and press Enter.
For example:
$ date [ENTER] Wed Dec 9 08:49:13 PST 1998 $
Here, the date command has been entered. This command displays the current day, date, time, and year. After the current date appears, notice that the $ character is displayed.
In this book, I use the $ character to indicate the prompt. Wherever you see a prompt, you can type the name of a command and press Enter. This executes the command that you type. While a command executes, the prompt is not displayed. When the command finishes executing, the prompt is displayed again.
Caution:
The $ character is a prompt for you to enter a command. It is not part of the command itself.For example, to execute the date command, you type the word date at the prompt, $. Dont type $ date. Depending on your version of UNIX, an error message might be displayed if you type $ date instead of date at the prompt.
Now look at another example of running a command:
$ who vathsa tty1 Dec 6 19:36 sveerara ttyp2 Dec 6 19:38 ranga ttyp0 Dec 9 09:23 $
Here, I entered the command who at the prompt. This command displays a list of all the people, or users, who are currently using the UNIX machine.
The first column of the output lists the usernames of the people who are logged in. On my system, you can see that there are three users, vathsa, sveerara, and ranga. The second column lists the terminals they are logged in to, and the final column lists the time they logged in.
The output varies from system to system. Try it on your system to see who is logged in.
For those readers who are not familiar with the process of logging in to a UNIX system, the details are discussed in Chapter 2, Script Basics.
The who and date commands are examples of simple commands. A simple command is one that you can execute by just giving its name at the prompt:
$ command
Here, command is the name of the command you want to execute. Simple commands in UNIX can be small commands like who and date, or they can be large commands like a Web browser or a spreadsheet program.You can execute most commands in UNIX as simple commands.
Previous | Table of Contents | Next |