Command (computing): Difference between revisions

Content deleted Content added
Examples: Less folksy (here some...); more accurate by identifying bash not just an OS (Unix)
Reverted 1 edit by 41.13.0.220 (talk): Edit summary doesn't correspond with edit
 
(5 intermediate revisions by 3 users not shown)
Line 1:
{{short description|External instruction to a computer program}}
{{redirect distinguish|System command|system call}}
{{other uses|Command (disambiguation)#Computing{{!}}Command §§ Computing}}
{{refimprove|date=May 2008 }}
In [[computing]], a '''command''' is an instruction received via an external [[Interface (computing)|interface]] that directs the behavior of a [[computer program]]. Commonly, commands are sent to a program via a [[command-line interface]], a [[scripting language|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 character|whitespace]]) with a prefix such as [[dash]] or [[Slash (punctuation)|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 (computing)|file]] by [[filename|name]] or [[file path|path]].
Specifically, the term ''command'' is used in [[imperative programming]] languages. The name arises because [[statement (programming)|statements]] in these languages are usually written in a manner similar to the [[imperative mood]] used in many [[natural language]]s. A statement in an imperative programming language would then be a sentence in a natural language, and the command would be the [[Predicate_(grammar)|predicate]].
 
The meaning ofterm ''command'' is highlysometimes dependentalso onused context.for Forinternal program exampleinstructions, somebut authorsoften referother toterms are more appropriate such as [[Conditional_statement (computer_programmingprogramming)|conditionalsstatement]], as[[Expression commands(computer science)|expression]], [[Function (computer programming)|function]], or [[Conditional (computer programming)|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 (Unix)|printf]], while theyin arePython calledit is via the ''expressionsfunction'' print().<ref>{{cite web | url = https://docs.python.org/3/library/functions.html#print | access-date = 23 October 2023 | title = Built-in Functions - print | publisher = python.org }}</ref> Further, some aspects of adjacent technology are conflated with commands. For example, conditional logic in Bash and Python is called an ''expression''<ref>{{cite web | url = https://docs.python.org/3/reference/expressions.html | access-date = 23 October 2023 | title = Conditional expressions | publisher = python.org }}</ref> or Bash<ref>{{cite web | url = https://www.gnu.org/software/bash/manual/html_node/Bash-Conditional-Expressions.html | access-date = 23 October 2023 | title = Bash Conditional expressions | publisher = gnu.org }}</ref> and ''statements'' in Java.<ref>{{cite web | url = https://docs.oracle.com/javase/tutorial/java/nutsandbolts/if.html | access-date = 23 October 2023 | title = The if-then and if-then-else Statements | publisher = oracle.com }}</ref>
Many programs allow specifically formatted [[Parameter (computer science)|arguments]], known as [[Command-line flag|flag]]s or options, which modify the default behaviour of the program, while further arguments may provide [[object (computing)|object]]s, such as [[file (computing)|file]]s, to act on. As an analogy to a [[natural language]], the flags are [[adverb]]s, while the other arguments are [[object (grammar)|grammatical object]]s.
 
==Distinction between ''command'' and [[Expression_(computer_science)|expression]], [[Statement_(computer_science)|statement]] and [[Function_(computer_programming)|function]]==
The meaning of ''command'' is highly dependent on context. For example, some authors refer to [[Conditional_(computer_programming)|conditionals]] as commands <ref>Maurizio Gabbrielli, Simone Martini (2010). Programming Languages - Principles and Paradigms. Springer London, ''6.3.2 Conditional Commands'', p. 140</ref> while they are called ''expressions'' in Python<ref>{{cite web | url = https://docs.python.org/3/reference/expressions.html | access-date = 23 October 2023 | title = Conditional expressions | publisher = python.org }}</ref> or Bash<ref>{{cite web | url = https://www.gnu.org/software/bash/manual/html_node/Bash-Conditional-Expressions.html | access-date = 23 October 2023 | title = Bash Conditional expressions | publisher = gnu.org }}</ref> and ''statements'' in Java.<ref>{{cite web | url = https://docs.oracle.com/javase/tutorial/java/nutsandbolts/if.html | access-date = 23 October 2023 | title = The if-then and if-then-else Statements | publisher = oracle.com }}</ref>
Similarly, writing to [[Standard_streams#Standard_output_(stdout)|stdout]] is done in Bash with the builtin ''command'' [[Printf_(Unix)|printf]], while it is done with the built-in ''function'' print() in Python.<ref>{{cite web | url = https://docs.python.org/3/library/functions.html#print | access-date = 23 October 2023 | title = Built-in Functions - print | publisher = python.org }}</ref>
 
==Examples==
Line 32 ⟶ 28:
</syntaxhighlight>
 
In shells such as [[Cmd.exe|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 (DOS command)|type]]''.<ref>{{cite web | url = https://ss64.com/nt/type.html | access-date = 14 March 2019 | title = Type - Display a text file - Windows CMD | publisher = SS64.com }}</ref>
 
<syntaxhighlight lang="batch">
Line 38 ⟶ 34:
</syntaxhighlight>
 
The following command prompt command lists the contents of the current directory via built-in command ''[[Dir (command)|dir]]''. The switch ''/Q'' modifies default behavior to include owner information.<ref>{{cite web | url = https://ss64.com/nt/dir.html | access-date = 14 March 2019 | title = DIR - list files and folders - Windows CMD | publisher = SS64.com }}</ref>
 
<syntaxhighlight lang="batch">
Line 45 ⟶ 41:
 
== See also ==
* [[Formal grammar]]
* [[Gesture recognition]]
* [[List of UnixPOSIX commands]]
* [[List of DOS commands]]
* [[Formal grammar]]
 
== References ==