The general pattern of a command line is: •
External commands run executables found in separate executable files. The command line interpreter searches for executable files with names matching the external command. • param1 …paramN — parameters provided by the user. The format and meaning of the parameters depends upon the command. In the case of external commands, the values of the parameters are delivered to the program as it is launched by the OS. Parameters may be either
arguments or
options. In this format, the delimiters between command-line elements are
whitespace characters and the end-of-line delimiter is the
newline delimiter. This is a widely used (but not universal) convention. 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,
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. 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 outputFile • doSomething how | doSomething how | doSomething 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 its own standard output (the screen) but to the named file. 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.
CLI and resource protection On some systems, such as
Unix-like systems or Windows, one can modify the set of available commands by modifying which paths appear in the
PATH environment variable or its equivalent. On Unix-like systems, the file containing the
executable or
script for a command also needs to be given
execute permission. The directories in the path variable are searched in the order they are given. By re-ordering the path, one can run e.g. instead of , when the default is the opposite. Renaming of the executables also works: people often rename their favourite editor to EDIT, for example. The command line allows one to restrict available commands, such as access to advanced internal commands. The
Bourne shell and workalikes such as
Bash can be run as a
restricted shell; among other things, this prohibits the user from modifying the PATH environment variable, so that if PATH is set to include only directories that contain only permissible commands, the user will only be able to run those commands. The Windows
CMD.EXE also supports restricting available commands. Often, shareware programs will limit the range of commands, including printing a command 'your administrator has disabled running batch files' from the prompt. Some CLIs, such as those in
network routers, have a hierarchy of
modes, with a different set of commands supported in each mode. The set of commands are grouped by association with security, system, interface, etc. In these systems the user might traverse through a series of sub-modes. For example, if the CLI had two modes called
interface and
system, the user might use the command
interface to enter the interface mode. At this point, commands from the system mode may not be accessible until the user exits the interface mode and enters the system mode. In IBM's flagship
MVS operating systems, the
Authorised Program Facility (
APF) allows certain
authorized programs to run with enhanced privileges, analogous to UID(0) in Unix-like systems.
TSO/E supports calling, e.g., authorized commands, but only for those commands, programs and services in an installation controlled list.
Command prompt after switch-on or hard reset A command prompt (or just
prompt) is a sequence of (one or more) characters used in a command-line interface to indicate readiness to accept commands. It literally
prompts the user to take action. A prompt usually ends with one of the characters $, %, #, A program can have many command-line arguments that identify sources or destinations of information, or that alter the operation of the program. When a command processor is active a program is typically invoked by typing its name followed by command-line arguments (if any). For example, in
Unix and
Unix-like environments, an example of a command-line argument is: rm file.s is a command-line argument which tells the program
rm to remove the file named . Some programming languages, such as
C,
C++ and
Java, allow a program to interpret the command-line arguments by handling them as string parameters in the
main function. Other languages, such as
Python, expose operating system specific
API (functionality) through the sys
module, and in particular sys.argv for
command-line arguments. In
Unix-like operating systems, a single hyphen used in place of a file name is a special value specifying that a program should handle data coming from the
standard input or send data to the
standard output.
Command-line option A
command-line option or simply
option (also known as a
flag or
switch) modifies the operation of a command; the effect is determined by the command's program. Options follow the command name on the command line, separated by, e.g., commas, spaces. Separators are not always required, such as Dir/? and DIR /? in DOS, which have the same effect Two hyphen-minus characters without following letters (--) may indicate that the remaining arguments should not be treated as options, which is useful for example if a file name itself begins with a hyphen, or if further arguments are meant for an inner command (e.g.,
sudo). Double hyphen-minuses are also sometimes used to prefix
long options where more descriptive option names are used. This is a common feature of
GNU software. The
getopt function and program, and the
getopts command are usually used for parsing command-line options. Unix command names, arguments and options are case-sensitive (except in a few examples, mainly where popular commands from other operating systems have been ported to Unix).
Option conventions in other systems FlexOS,
4680 OS and
4690 OS use -.
CP/M typically used [.
Conversational Monitor System (CMS) uses a single
left parenthesis to separate options at the end of the command from the other arguments. For example, in the following command the options indicate that the target file should be replaced if it exists, and the date and time of the source file should be retained on the copy: COPY source file a target file b (REPLACE OLDDATE)
OS/360 operator commands use a comma separated list of positional and keyword parameters; only documented command and keyword abbreviations are valid. Keyword values are separated from the keywords with equal signs.
TSO commands use a space separated list of positional and keyword parameters; keywords may be truncated to any unique sub-string. Only documented command abbreviations are valid. Keyword values are inside parentheses.
Data General's CLI under their
RDOS,
AOS, etc. operating systems, as well as the version of CLI that came with their
Business Basic, uses only / as the switch character, is case-insensitive, and allows
local switches on some arguments to control the way they are interpreted, such as has the global option to the macro assembler command to append user symbols, but two local switches, one to specify LIB should be skipped on pass 2 and the other to direct listing to the printer, $LPT.
Built-in usage help One of the criticisms of a CLI is the lack of cues to the user as to the available actions. In contrast, GUIs usually inform the user of available actions with menus, icons, or other visual cues. To overcome this limitation, many CLI programs display a
usage message, typically when invoked with no arguments or one of ?, -?, -h, -H, /?, /h, /H, /Help, -help, or --help. However, entering a program name without parameters in the hope that it will display usage help can be hazardous, as programs and scripts for which command line arguments are optional will execute without further notice. Although desirable at least for the help parameter, programs may not support all option lead-in characters exemplified above. Under DOS, where the default
command-line option character can be changed from / to -, programs may query the
SwitChar API in order to determine the current setting. So, if a program is not hardwired to support them all, a user may need to know the current setting even to be able to reliably request help. If the SwitChar has been changed to - and therefore the / character is accepted as an alternative path delimiter at the DOS command line, programs might misinterpret options like /h or /H as paths rather than help parameters. However, if given as the first or only parameter, most DOS programs will, by convention, accept it as a request for help regardless of the current SwitChar setting. In some cases, different levels of help can be selected for a program. Some programs supporting this allow to give a verbosity level as an optional argument to the help parameter (as in /H:1, /H:2, etc.) or they give just a short help on help parameters with question mark and a longer help screen for the other help options. Depending on the program, additional or more specific help on accepted parameters is sometimes available by either providing the parameter in question as an argument to the help parameter or vice versa (as in /H:W or in /W:? (assuming /W would be another parameter supported by the program)). In a similar fashion to the help parameter, but much less common, some programs provide additional information about themselves (like mode, status, version, author, license or contact information) when invoked with an
about parameter like -!, /!, -about, or --about. Since the ? and ! characters typically also serve other purposes at the command line, they may not be available in all scenarios, therefore, they should not be the only options to access the corresponding help information. displayed on a
VT100 If more detailed help is necessary than provided by a program's built-in internal help, many systems support a dedicated external
help command" command (or similar), which accepts a command name as calling parameter and will invoke an external help system. In the DR-DOS family, typing /? or /H at the
COMMAND.COM prompt instead of a command itself will display a dynamically generated list of available internal commands;
4DOS and
NDOS support the same feature by typing ? at the prompt (which is also accepted by newer versions of DR-DOS COMMAND.COM); internal commands can be individually disabled or reenabled via SETDOS /I. In addition to this, some newer versions of DR-DOS COMMAND.COM also accept a ?% command to display a list of available built-in
pseudo-environment variables. Besides their purpose as quick help reference this can be used in batchjobs to query the facilities of the underlying command-line processor.
Command description syntax Built-in usage help and
man pages commonly employ a small syntax to describe the valid command form: • angle brackets for
required parameters: ping • square brackets for
optional parameters: mkdir [-p] • ellipses for
repeated items: cp [source2…] • vertical bars for
choice of items: netstat {-t|-u} Notice that these characters have different meanings than when used directly in the shell. Angle brackets may be omitted when confusing the parameter name with a literal string is not likely.
The space character In many areas of computing, but particularly in the command line, the
space character can cause problems as it has two distinct and incompatible functions: as part of a command or parameter, or as a parameter or name
separator. Ambiguity can be prevented either by prohibiting embedded spaces in file and directory names in the first place (for example, by substituting them with
underscores _), or by enclosing a name with embedded spaces between quote characters or using an
escape character before the space, usually a
backslash (\). For example :Long path/Long program name Parameter one Parameter two … is ambiguous (is
program name part of the program name, or two parameters?); however :Long_path/Long_program_name Parameter_one Parameter_two …, :LongPath/LongProgramName ParameterOne ParameterTwo …, :"Long path/Long program name" "Parameter one" "Parameter two" … and :Long\ path/Long\ program\ name Parameter\ one Parameter\ two … are not ambiguous.
Unix-based operating systems minimize the use of embedded spaces to minimize the need for quotes. In
Microsoft Windows, one often has to use quotes because embedded spaces (such as in directory names) are common. == Command-line interpreter ==