Commands

Overview

At a high-level, command-line commands represent a piece of code that:

  1. Optionally receives input data, then
  2. Optionally performs an operation on that data, then
  3. Passes the (possibly modified) data to the output, and
  4. Optionally generates an error message.

The following diagram provides a useful representation of this:

The "natural" flow goes from the input, to the command, then to the output. If an error occurs, then information about that error is sent to the error. With this diagram in mind, let's proceed to see some examples that will help solidify this concept.

Executing Commands

Commands are executed from the command-line by typing the name of the command, possibly followed by options and/or arguments.

Arguments provide the command with information that it needs to perform its task. For example, a command that operates on a file might be passed the name of the file to perform those operations on.

Options provide "knobs" that allow the user to customize how the script behaves.

The combination of command, arguments, and options can be combined into a call signature, which describes the format to be used when calling the command.

As a simple example, the echo command is often called with a single string as an argument:

·
·
·
·
·
·
·
ninja$: echo Hello World!
Hello·World!
ninja$:  

which takes the argument (Hello World!) and passes it to the output which, by default, prints the output to the terminal screen.

In the next section we will see how to use this output as the input for other commands.