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.[1]

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.[2]

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.[3][4] For example, printing a message in Bash is via the command printf, while in Python it is via the function print().[5] Further, some aspects of adjacent technology are conflated with commands. For example, conditional logic in Bash and Python is called an expression[6][7] and statements in Java.[8][9]

Examples

edit

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.[10] The following bash command changes the working directory to /home/pete by invoking the program cd:

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.

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 as command prompt, DOS, and OS/2 some commands are built-in: not implemented as a separate program.[11] 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.[12]

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.[13]

dir /Q

See also

edit

References

edit
  1. ^ Kernighan, Brian W.; Pike, Rob (1984). The UNIX Programming Environment. Prentice Hall. ISBN 978-0-13-937681-8.
  2. ^ Sobell, Mark G. (2014). A Practical Guide to Linux Commands, Editors, and Shell Programming (3rd ed.). Prentice Hall. ISBN 978-0-13-308504-4.
  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 (5th ed.). O’Reilly Media. ISBN 978-1-449-35573-9.
  5. ^ "Built-in Functions - print". python.org. Retrieved 23 October 2023.
  6. ^ "Conditional expressions". python.org. Retrieved 23 October 2023.
  7. ^ "Bash Conditional expressions". gnu.org. Retrieved 23 October 2023.
  8. ^ "The if-then and if-then-else Statements". oracle.com. Retrieved 23 October 2023.
  9. ^ Horstmann, Cay S.; Cornell, Gary (2018). Core Java: Volume I – Fundamentals (11th ed.). Prentice Hall. ISBN 978-0-13-516630-7.
  10. ^ "Bash Reference Manual". Free Software Foundation. 2023.
  11. ^ "Windows Command Line Reference". Microsoft. 2023.
  12. ^ "Type - Display a text file - Windows CMD". SS64.com. Retrieved 14 March 2019.
  13. ^ "DIR - list files and folders - Windows CMD". SS64.com. Retrieved 14 March 2019.
edit

📚 Artikel Terkait di Wikipedia

Command-line interface

interface (either a user interface (command-line interface, GUI, etc...) or a programming interface) to a command interpreter and processor and to the

Conditional (computer programming)

control flow. Many programming languages (such as C) have distinct conditional statements and expressions. In pure functional programming, a conditional expression

Standard Commands for Programmable Instruments

Commands for Programmable Instruments (SCPI; often pronounced "skippy") defines a standard for syntax and commands to use in controlling programmable

Glob (programming)

the expanded list of file paths to the command for execution. Glob was originally written in the B programming language. It was the first piece of mainline

Control Language

select all commands in a library then prompt this command and enter the special value *ALL. The following is a sample of CL programming. The program interactively

Command-line completion

commands. Command line interpreters are programs that allow a user to interact with the underlying operating system by typing commands at a command prompt

List of POSIX commands

This is a list of the shell commands of the most recent version of the Portable Operating System Interface (POSIX) – IEEE Std 1003.1-2024 which is part

Logo (programming language)

Logo is an educational programming language, designed in 1967 by Wally Feurzeig, Seymour Papert, and Cynthia Solomon. The name was coined by Feurzeig