Main index

Introducing UNIX and Linux


Introduction to shells

Overview
Why do we need a shell?
Shell syntax
      Types of shell command
      Simple commands
      Pipelines
      Grouping commands
      Exit status
      List commands
Arithmetic
      Operators and functions
Making decisions
      The 'test' statement
            Operators used by 'test'
      The 'if' statement
Loops
      'For' loops
      'While' and 'until' loops
Searching for files
      Arguments to 'find'
Formatted output
      Arguments to 'printf'
Passing information to scripts
      Scripts with arguments
      Parameter expansion
Summary
Exercises

Types of shell command

We must now distinguish between two concepts - utilities and commands. A utility is the name of a program, such as wc, date or uname. A command is an instruction to the shell to perform a task. A very simple command may well just be the name of a utility, but in general is more complex. Consider

uname -a >outputfile

which will display the 'vital statistics' of the system you are running the command on, redirecting the output to file outputfile. The command

uname -a >outputfile

comprises utility uname with argument -a, and standard output redirected to outputfle. In order to combine the utilities we have met, and the sorts of command we already know about, into more complex structures, we need to be very precise about what sorts of command are available. The shell allows five different types of command:

  • simple command
  • pipeline
  • list command
  • function definition
  • compound command.

When we use the word command, we mean any of the above five types of command. We discuss all of the above in this chapter, with the exception of functions, which are covered later on. Of the five types of command, we will explicitly define the first four, and all other commands we introduce come under the heading of compound commands. Don't worry if these names look complex - we need them so that later on we can be completely unambiguous when we discuss shells, and you may then need to refer back to here. For now, you should remember simply that command types are neatly categorised.


Copyright © 2002 Mike Joy, Stephen Jarvis and Michael Luck