Swit Char - Anatomy of A Shell CLI

Anatomy of A Shell CLI

The general pattern of an OS command line interface is:

prompt command param1 param2 param3 ... paramN

  • Prompt - generated by the program to provide context for the client.
  • Command - provided by the client. Commands are usually one of three classes:
    1. Internal - recognized and processed by the command line interpreter itself and not dependent upon any external executable file.
    2. Included - A separate executable file generally considered part of the operating environment and always included with the OS.
    3. External - External executable files not part of the basic OS, but added by other parties for specific purposes and applications.
  • param1 ...paramN - Optional parameters provided by the client. The format and meaning of the parameters depends upon the command issued. In the case of Included or External commands, the values of the parameters are delivered to the process (specified by the Command) as it is launched by the OS. Parameters may be either Arguments or Options.

In this example, the delimiters between command line elements are whitespace characters and the end-of-line delimiter is the newline delimiter. This is a widely (but not universally) used convention for command-line interfaces.


A CLI can generally be considered as consisting of syntax and semantics. The syntax is the grammar that all commands must follow. In the case of operating systems (OS), MS-DOS and Unix each define their own set of rules that all commands must follow. In the case of embedded systems, each vendor, such as Nortel, Juniper Networks or Cisco Systems, defines their own proprietary set of rules that all commands within their CLI conform to. These rules also dictate how a user navigates through the system of commands. The semantics define what sort of operations are possible, on what sort of data these operations can be performed, and how the grammar represents these operations and data—the symbolic meaning in the syntax.

Two different CLIs may agree on either syntax or semantics, but it is only when they agree on both that they can be considered sufficiently similar to allow users to use both CLIs without needing to learn anything, as well as to enable re-use of scripts.

A simple CLI will display a prompt, accept a "command line" typed by the user terminated by the Enter key, then execute the specified command and provide textual display of results or error messages. Advanced CLIs will validate, interpret and parameter-expand the command line before executing the specified command, and optionally capture or redirect its output.

Unlike a button or menu item in a GUI, a command line is typically self-documenting, stating exactly what the user wants done. In addition, command lines usually include many defaults that can be changed to customize the results. Useful command lines can be saved by assigning a character string or alias to represent the full command, or several commands can be grouped to perform a more complex sequence – for instance, compile the program, install it, and run it — creating a single entity, called a command procedure or script which itself can be treated as a command. These advantages mean that a user must figure out a complex command or series of commands only once, because they can be saved, to be used again.

The commands given to a CLI shell are often in one of the following forms:

  • doSomething how toFiles
  • doSomething how sourceFile destinationFile
  • doSomething how < inputFile > outputFile
  • doSomething how | doSomething how | do Something how > outputFile

where doSomething is, in effect, a verb, how an adverb (for example, should the command be executed "verbosely" or "quietly") and toFiles an object or objects (typically one or more files) on which the command should act. The '>' in the third example is a redirection operator, telling the command-line interpreter to send the output of the command not to the screen but to the file named on the right of the '>'. This will overwrite the file. Using '>>' will redirect the output and append it to the file. Another redirection operator is the vertical bar ('|'), which creates a pipeline where the output of one command becomes the input to the next command.

Read more about this topic:  Swit Char

Famous quotes containing the words anatomy and/or shell:

    But a man must keep an eye on his servants, if he would not have them rule him. Man is a shrewd inventor, and is ever taking the hint of a new machine from his own structure, adapting some secret of his own anatomy in iron, wood, and leather, to some required function in the work of the world. But it is found that the machine unmans the user. What he gains in making cloth, he loses in general power.
    Ralph Waldo Emerson (1803–1882)

    If there was one egg in it there were nine,
    Torpedo-like, with shell of gritty leather,
    All packed in sand to wait the trump together.
    Robert Frost (1874–1963)