Skip to content
Surf Wiki
Save to docs
technology/computing

From Surf Wiki (app.surf) — the open knowledge base

Command (computing)

External instruction to a computer program


Summary

External instruction to a computer program

In computing, a command is a high-level 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. For example, printing a message in Bash is via the command printf, while in Python it is via the function print(). Further, some aspects of adjacent technology are conflated with commands. For example, conditional logic in Bash and Python is called an expression and statements in Java.

Examples

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:

BASH
cd /home/pete

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

BASH
echo "Hello World"

The following demonstrates how the default behavior of a command is modified with a switch. The switch causes the command to treat characters prefixed with a backslash as the associated control character. In this case results in a tab character.

BASH
echo -e "Hello\tWorld"

In shells such as command prompt, DOS, and OS/2 some commands are built-in: 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.

BATCH
type readme.txt

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.

BATCH
dir /Q

References

References

  1. (1984). "The UNIX Programming Environment". Prentice Hall.
  2. Sobell, Mark G.. (2014). "A Practical Guide to Linux Commands, Editors, and Shell Programming". Prentice Hall.
  3. Maurizio Gabbrielli, Simone Martini (2010). Programming Languages - Principles and Paradigms. Springer London, ''6.3.2 Conditional Commands'', p. 140
  4. Lutz, Mark. (2013). "Learning Python". O’Reilly Media.
  5. "Built-in Functions - print". python.org.
  6. "Conditional expressions". python.org.
  7. "Bash Conditional expressions". gnu.org.
  8. "The if-then and if-then-else Statements". oracle.com.
  9. (2018). "Core Java: Volume I – Fundamentals". Prentice Hall.
  10. (2023). "Bash Reference Manual". Free Software Foundation.
  11. (2023). "Windows Command Line Reference". Microsoft.
  12. "Type - Display a text file - Windows CMD". SS64.com.
  13. "DIR - list files and folders - Windows CMD". SS64.com.
Wikipedia Source

This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page.

Want to explore this topic further?

Ask Mako anything about Command (computing) — get instant answers, deeper analysis, and related topics.

Research with Mako

Free with your Surf account

Content sourced from Wikipedia, available under CC BY-SA 4.0.

This content may have been generated or modified by AI. CloudSurf Software LLC is not responsible for the accuracy, completeness, or reliability of AI-generated content. Always verify important information from primary sources.

Report