Command (computing)

Revision as of 00:34, 3 April 2025 by imported>Beland (convert special characters found by Wikipedia:Typo Team/moss (via WP:JWB))
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

Template:Short description Template:Redirect distinguish {{#invoke:other uses|otheruses}} Template:Refimprove In computing, a command is an instruction received via an external interface that directs the behavior of a computer program. Commonly, commands are sent to a program via a command-line interface, a script, a network protocol, or as an event triggered in a graphical 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, an option or a flag is a name (without whitespace) with a prefix such as dash or slash 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. A parameter 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 a file by name or path.

The term command is sometimes also used for internal program instructions, but often other terms are more appropriate such as statement, expression, function, or conditional.<ref>Maurizio Gabbrielli, Simone Martini (2010). Programming Languages - Principles and Paradigms. Springer London, 6.3.2 Conditional Commands, p. 140</ref> For example, printing a message in Bash is via the command printf, while in Python it is via the function print().<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> Further, some aspects of adjacent technology are conflated with commands. For example, conditional logic in Bash and Python is called an expression<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref><ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> and statements in Java.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

ExamplesEdit

A notable context in which commands are prevalent is the operating system shell. Commonly, the shell dispatches a command to a program that has a file name matching the first parameter. In a Unix shell (such as bash and many related variants), the match must be exact including case. The following bash command changes the working directory to /home/pete by invoking the program cd: <syntaxhighlight lang="bash"> cd /home/pete </syntaxhighlight>

The following bash command writes "Hello World" via program echo to standard output Template:Endash typically the terminal. Quotes around the two words indicate that the phrase is treated as a single parameter.

<syntaxhighlight lang="bash"> echo "Hello World" </syntaxhighlight>

The following demonstrates how the default behavior of a command is modified with a switch. The switch <syntaxhighlight lang="text" class="" style="" inline="1">-e</syntaxhighlight> causes the command to treat characters prefixed with a backslash as the associated control character. In this case <syntaxhighlight lang="text" class="" style="" inline="1">\t</syntaxhighlight> results in a tab character.

<syntaxhighlight lang="bash"> echo -e "Hello\tWorld" </syntaxhighlight>

In shells such as command prompt, DOS, and OS/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 file readme.txt via the built-in command type.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

<syntaxhighlight lang="batch"> type readme.txt </syntaxhighlight>

The following command prompt command lists the contents of the current directory via built-in command dir. The switch /Q modifies default behavior to include owner information.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

<syntaxhighlight lang="batch"> dir /Q </syntaxhighlight>

See alsoEdit

ReferencesEdit

Template:Reflist

External linksEdit

Template:Sister project

Template:Unix commands Template:Windows commands