This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed. Find sources: "Command" computing – news ·newspapers ·books ·scholar ·JSTOR(May 2008) (Learn how and when to remove this message) |
Incomputing, acommand is an instruction received via an externalinterface that directs the behavior of acomputer program. Commonly, commands are sent to a program via acommand-line interface, ascript, anetwork protocol, or as an event triggered in agraphical user interface.
Many commands support arguments to specify input and to modify default behavior. Terminology and syntax varies but there are notable common approaches. Typically, anoption or aflag is a name (withoutwhitespace) with a prefix such asdash orslash that modifies default behavior. An option might have a required value that follows it. Typically, flag refers to an option that does not have a following value. Aparameter is an argument that specifies input to the command and its meaning is based on its position in the command line relative to other parameters; generally ignoring options. A parameter can specify anything, but often it specifies afile byname orpath.
The termcommand is sometimes also used for internal program instructions, but often other terms are more appropriate such asstatement,expression,function, orconditional.[1] For example, printing a message in Bash is via thecommandprintf, while in Python it is via thefunction print().[2] Further, some aspects of adjacent technology are conflated with commands. For example, conditional logic in Bash and Python is called anexpression[3][4] andstatements in Java.[5]
A notable context in which commands are prevalent is theoperating systemshell. Commonly, the shell dispatches a command to a program that has a file name matching the first parameter. In aUnix shell (such asbash and many related variants), the match must be exact including case. The following bash command changes theworking directory to/home/pete by invoking the programcd:
cd/home/pete
The following bash command writes "Hello World" via programecho tostandard output – typically theterminal. Quotes around the two words indicate that the phrase is treated as a single parameter.
echo"Hello World"
The following demonstrates how the default behavior of a command is modified with a switch. The switch-e
causes the command to treat characters prefixed with a backslash as the associated control character. In this case\t
results in a tab character.
echo-e"Hello\tWorld"
In shells such ascommand prompt,DOS, andOS/2 some commands are built-in; are not implemented as a separate program. But, if a command is not built-in, then the shell dispatches to a program that has an executable extension (such as.exe) and base name matching the first parameter ignoring case. The following command prompt command displays the content of filereadme.txt via the built-in commandtype.[6]
type readme.txt
The following command prompt command lists the contents of the current directory via built-in commanddir. The switch/Q modifies default behavior to include owner information.[7]
dir /Q