Jump to content

Command (computing): Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
subjective ce
 
(110 intermediate revisions by 87 users not shown)
Line 1: Line 1:
{{short description|Directive to a computer program}}
{{unreferenced|date=May 2008}}
{{redirect distinguish|System command|system call}}
In [[computing]], a '''command''' is a directive to a computer program acting as an interpreter of some kind, in order to perform a specific task. Most commonly a command is a directive to some kind of [[command-line interface]], such as a [[shell (computing)|shell]].
{{other uses|Command (disambiguation)#Computing{{!}}Command#Computing}}
{{refimprove|date=May 2008 }}
In [[computing]], a '''command''' is a directive to a computer program to perform a specific task. It may be issued via a [[command-line interface]] or as input to a network service as part of a [[network protocol]], or as an event triggered in a [[graphical user interface]].


Specifically, the term ''command'' is used in [[imperative programming|imperative]] [[computer language]]s. These languages are called this, because [[statement (programming)|statements]] in these languages are usually written in a manner similar to the [[imperative mood]] used in many [[natural language]]s. If one views a statement in an [[imperative language]] as being like a sentence in a natural language, then a command is generally like a verb in such a language.
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]].


Many programs allow specially formatted [[command-line argument|arguments]], known as flags or options, which modify the default behaviour of the command, while further [[Parameter (computer science)|arguments]] describe what the command acts on. Comparing to a natural language: the flags are adverbs, whilst the other arguments are [[object (grammar)|object]]s.
Many programs allow specifically formatted [[Parameter (computer science)|arguments]], known as flags or options, which modify the default behaviour of the program, while further arguments may provide objects, such as files, to act on. As an analogy to a natural language, the flags are adverbs, while the other arguments are [[object (grammar)|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==
==Examples==
Here are some commands given to a [[command-line interpreter]] ([[Unix shell]]).
Here are some commands given to a [[command-line interpreter]] ([[Unix shell]]).


The following command changes the user's place in the [[directory tree]] from their current position to the directory <tt>/home/pete</tt>. <tt>[[Cd (command)|cd]]</tt> is the command and <tt>/home/pete</tt> is the argument:
The following command changes the user's working position in the [[directory tree]] to the directory ''/home/pete''. The utility program is ''[[Cd (command)|cd]]'' and the argument is ''/home/pete'':
<source lang="bash">
cd /home/pete
cd /home/pete
</source>


The following command prints the text <tt>Hello World</tt> out to the [[standard output]] stream, which, in this case, will just print the text out on the screen. <tt>[[Echo (command)|echo]]</tt> is the command and <tt>"Hello World"</tt> is the argument. The quotes are used to prevent <tt>Hello</tt> and <tt>World</tt> being treated as separate arguments:
The following command prints the text ''Hello World'' on the [[standard output]] stream, which, in this case, just prints the text on the screen. The program name is [[Echo (command)|echo]] and the argument is "Hello World". The quotes are used to prevent ''Hello'' and ''World'' being treated as separate tokens:
<source lang="bash">
echo "Hello World"
echo "Hello World"
</source>


The following commands are equivalent. They list files in the directory <tt>/bin</tt>. <tt>[[ls]]</tt> is the command, <tt>[[Filesystem Hierarchy Standard|/bin]]</tt> is the argument and there are three flags: <tt>-l</tt>, <tt>-t</tt> and <tt>-r</tt>:
The following commands are equivalent. They list files in the directory ''/bin''. The program is ''[[ls]]'', having three flags (''l'', ''t'', ''r''), and the argument is the directory ''[[Filesystem Hierarchy Standard|/bin]]'':
ls -l -t -r /bin
<source lang="bash">
ls -l -t -r /lvl 100
ls -ltr /bin
ls -ltr /bin
</source>


The following command displays the contents of the files <tt>ch1.txt</tt> and <tt>ch2.txt</tt>. <tt>[[cat (Unix)|cat]]</tt> is the command and <tt>ch1.txt</tt> and <tt>ch2.txt</tt> are both arguments.
The following command displays the contents of the files ''ch1.txt'' and ''ch2.txt''. The program name is ''[[cat (Unix)|cat]]'', having two file name arguments:
<source lang="bash">
cat ch1.txt ch2.txt
cat ch1.txt ch2.txt
</source>


Here are some commands for the [[DOS]], [[OS/2]] and [[Microsoft Windows]] [[Cmd.exe|command prompt]] processor. The following command displays the contents of the file ''readme.txt''. The program name is ''[[TYPE (DOS command)|type]]'' and the argument is ''readme.txt''.<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>
The following command lists all the contents of the current directory. <tt>[[Dir (command)|dir]]</tt> is the command and "A" is a flag. There is no argument. Here are some commands given to a different command-line interpreter (the [[DOS]], [[OS/2]] and [[Microsoft Windows]] command prompt). Notice that the flags are identified differently but that the concepts are the same:
type readme.txt
<source lang="bash">
dir /A
</source>


The following command displays the contents of the file readme.txt. <tt>[[Type (command)|type]]</tt> is the command. "readme.txt" is the argument. "P" is a parameter...
The following command lists the contents of the current directory. The program name is ''[[Dir (command)|dir]]'', and ''Q'' is a flag requesting that the owner of each file also be listed.<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>
dir /Q

<source lang="bash">
type /P readme.txt
</source>


== See also ==
== See also ==
* [[List of Unix programs]]
* [[Gesture recognition]]
* [[List of Unix commands]]
* [[List of DOS commands]]
* [[List of DOS commands]]
* [[Formal grammar]]
* [[Formal grammar]]

== References ==
{{Reflist}}


== External links ==
== External links ==
{{Wikibooks|Guide to Windows commands}}
{{Wikibooks|Guide to Windows commands}}
* [http://foldoc.org/index.cgi?query=command command] from [[FOLDOC]]
*[http://foldoc.org/command command] from [[FOLDOC]]
*[https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/windows-commands Windows Commands | Microsoft Docs]

{{Unix commands}}
{{Windows commands}}


[[Category:User interfaces]]
[[Category:User interfaces]]
[[Category:Computing terminology]]
[[Category:Computing terminology]]
[[Category:Computing commands| ]]
[[Category:Computing commands| ]]

[[de:Instruktion]]

Latest revision as of 17:17, 11 December 2024

In computing, a command is a directive to a computer program to perform a specific task. It may be issued via a command-line interface or as input to a network service as part of a network protocol, or as an event triggered in a graphical user interface.

Specifically, the term command is used in imperative programming languages. The name arises because statements in these languages are usually written in a manner similar to the imperative mood used in many natural languages. A statement in an imperative programming language would then be a sentence in a natural language, and the command would be the predicate.

Many programs allow specifically formatted arguments, known as flags or options, which modify the default behaviour of the program, while further arguments may provide objects, such as files, to act on. As an analogy to a natural language, the flags are adverbs, while the other arguments are objects.

Distinction between command and expression, statement and function

[edit]

The meaning of command is highly dependent on context. For example, some authors refer to conditionals as commands [1] while they are called expressions in Python[2] or Bash[3] and statements in Java.[4] Similarly, writing to stdout is done in Bash with the builtin command printf, while it is done with the built-in function print() in Python.[5]

Examples

[edit]

Here are some commands given to a command-line interpreter (Unix shell).

The following command changes the user's working position in the directory tree to the directory /home/pete. The utility program is cd and the argument is /home/pete:

cd /home/pete

The following command prints the text Hello World on the standard output stream, which, in this case, just prints the text on the screen. The program name is echo and the argument is "Hello World". The quotes are used to prevent Hello and World being treated as separate tokens:

echo "Hello World"

The following commands are equivalent. They list files in the directory /bin. The program is ls, having three flags (l, t, r), and the argument is the directory /bin:

ls -l -t -r  /bin
ls -ltr  /bin

The following command displays the contents of the files ch1.txt and ch2.txt. The program name is cat, having two file name arguments:

cat ch1.txt ch2.txt

Here are some commands for the DOS, OS/2 and Microsoft Windows command prompt processor. The following command displays the contents of the file readme.txt. The program name is type and the argument is readme.txt.[6]

type readme.txt

The following command lists the contents of the current directory. The program name is dir, and Q is a flag requesting that the owner of each file also be listed.[7]

dir /Q

See also

[edit]

References

[edit]
  1. ^ Maurizio Gabbrielli, Simone Martini (2010). Programming Languages - Principles and Paradigms. Springer London, 6.3.2 Conditional Commands, p. 140
  2. ^ "Conditional expressions". python.org. Retrieved 23 October 2023.
  3. ^ "Bash Conditional expressions". gnu.org. Retrieved 23 October 2023.
  4. ^ "The if-then and if-then-else Statements". oracle.com. Retrieved 23 October 2023.
  5. ^ "Built-in Functions - print". python.org. Retrieved 23 October 2023.
  6. ^ "Type - Display a text file - Windows CMD". SS64.com. Retrieved 14 March 2019.
  7. ^ "DIR - list files and folders - Windows CMD". SS64.com. Retrieved 14 March 2019.
[edit]