Command line interface
From Wikipedia, the free encyclopedia

A command line interface or CLI is a tool for interacting with computers, often using a text terminal or remote shell client software, such as PuTTY. CLIs originated when teletype machines were connected to computers in the 1950s. Offering immediate interaction and feedback, they are an advancement over mechanical punch card technology.
With cathode ray tubes making way for graphics development, CLIs continues to coevolve with graphical user interfaces (GUIs) like Microsoft Windows, Mac OS, and the X Window System.
Contents |
[edit] Usage
CLIs are often used by programmers and system administrators (especially in Unix-based operating systems), in engineering and scientific environments, and by a smaller subset of technically advanced home users. CLIs are also popular among people with visual disability[citation needed].
A program that implements such interface is often called a command line interpreter or shell. Examples include the various Unix shells (sh, ksh, csh, tcsh, bash, etc.), the historical CP/M, and DOS's command.com ("Command Prompt"), the latter two based heavily on DEC's RSX and RSTS CLIs.
In November 2006, Microsoft released version 1.0 of Windows PowerShell (formerly codenamed Monad), which combined features of traditional Unix shells with their object-oriented .NET Framework. MinGW and Cygwin are open source packages for Windows that offers a Unix like CLI. Microsoft provides a Unix CLI for Windows through their Services for UNIX add-on.
The latest versions of the Macintosh operating system are based on a variation of UNIX called Darwin. On these computers, users can access a UNIX-like command prompt called terminal found in the /Applications/Utilities folder.
[edit] Anatomy of a CLI
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, each define 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, and on what sort of data these operations can be performed.
It may be possible for two different CLIs to 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 systems without needing to relearn anything as well as enable re-use of scripts.
In its simplest form, a CLI displays a prompt, the user types a command on the keyboard and executes the command (usually with the Enter key), and the computer executes the command, providing textual 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. Command-line commands 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 command, called a command procedure. These advantages mean that a user has to figure out a command or series of commands only once, because they can be saved to use again.
The commands given to a CLI are often of the form
[doSomething] [how] [toFiles]
or
[doSomething] [how] [sourceFile] [destinationFile]
or
[doSomething] [how] < [inputFile] > [outputFile]
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 second example is a redirection token, 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 '>'. Another redirection token is the pipe ('|'), which tells the CLI to use the output of one command as the input to the next command; this "operator-stream" mechanism can be very powerful.
Another aspect of a CLI is navigation. In some CLIs, the commands issued are decoupled from their conceptual place within the command hierarchy. This usually involves being able to specify relative or absolute paths to command and data. Examples of this sort of system include MS-DOS and UNIX, which both provide forms of a change directory command to take users through a set of directories that hold command and data. Other CLIs limit the set of commands that a user can perform to the place within the command hierarchy. The place within the hierarchy and the options available are often referred to as a mode. In these systems the user might traverse through a series of sub-hierarchies, each with their own set of commands. For example, if the CLI had two modes called interfaces and system, the user would enter the word 'interface' at the command prompt and then enter an interface mode. At this point system commands are not accessible and would not be accessible until the user explicitly exits the interface model. Within the interface mode, the user would have access to a series of commands, and perhaps additional command modes.
[edit] Command prompt
A command prompt (or just prompt) is a sequence of (one or more) characters used in a command line interface to indicate availability to accept commands. Command prompts usually end with one of the characters $, %, #, :, > and often include other information, such as the path of the current working directory.
It is common for prompts to be modifiable by the user. Depending on the environment, they may include colors, special characters, and other elements like the current time, in order, for instance, to make the prompt more informative or visually pleasing, or to easily distinguish sessions on various machines.
In MS-DOS and in the Windows command line interpreter the prompt is modifiable by issuing a prompt
command or by changing the value of the %PROMPT%
environment variable. The default C:\>
style is obtained, for instance, with "prompt $P$G
".
On many Unix systems, the $PS1 variable can be used, although other variables also may have an impact on what appears on the screen (depending on what shell is being used). In the bash shell, a prompt of the form
[time] user@host: work_dir $
could be set by issuing the command
export PS1='[\t] \u@\H: $(pwd) $'
In zsh the $RPROMPT variable controls an optional "prompt" on the right hand side of the display. It is not a real prompt in that the location of text entry does not change. It is used to display information on the same line as the prompt, but right justified.
[edit] CLI vs GUI

- CLI environments tend to consume less resources than GUIs.
- CLI applications typically use standard I/O (stdio), allowing them to easily work together in scripts.
- Some applications provide both a CLI and a GUI.
- CLIs can be unsuitable for some applications such as raster painting programs
- GUIs are better suited for devices without keyboards such as PDAs, electronic voting machines, ATMs, arcade machines, electronic gambling machines, or kiosks.
[edit] References
[edit] See also
[edit] External links
- Linux Command Line — a list of unix shell commands.
- Command Line Warriors — an open site about Command Line Computing.
- The Interaction-Design.org Encyclopedia entry on Interaction Styles, comparing Command Line Interfaces with other Interaction Styles
- Command lines versus GUIs
- The Windows XP Command Line, Batch Files, and Scripting
- "GetPot. Object oriented command line parsing." Library available for C++, Python, Java, and Ruby.
- "Object-Oriented Command Line Interfaces" — Article describing the use of the TE-Common CLI library for Java (also available for .NET).
- PHP Command Line Interface — All about PHP CLI SAPI (using PHP in command line).
- - Setting up the console for Windows - A basic guide to setting up and using the command line for Windows.
- The Command Line -- The Best Newbie Interface? -- essay/memoir alleging/demonstrating that the CLI is actually more intuitive than the GUI, at least for adult newbies.
Categories: Articles lacking sources from February 2007 | All articles lacking sources | Cleanup from February 2007 | All pages needing cleanup | Articles to be merged since February 2007 | Articles with unsourced statements since February 2007 | All articles with unsourced statements | NPOV disputes | Articles lacking sources from August 2006 | User interface | Software engineering | Software architecture