Command-line argument

Command-line argument

In computer command line interfaces, a command line argument is an argument sent to a program being called. In general, a program can take any number of command line arguments, which may be necessary for the program to run, or may even be ignored, depending on the function of that program.

For example, in Unix and Unix-like environments, an example of a command-line argument is:

rm file.s

"file.s" is a command line argument which tells the program rm to remove the file "file.s".

Programming languages such as C, C++ and Java allow a program to interpret the command line arguments by handling them as string parameters in the main function.

Command-line switch

A command line switch or simply switch (also known as a flag, an option, or a command line parameter) is an indication by a user that a computer program should change its default behaviour.

For example, in the OpenVMS operating system, the command directory is used to list the files inside a directory. By default—that is, when the user simply types directory—it will list only the names of the files. By adding the "switch" /owner (to form the command directory/owner), the user can instruct the directory command to also display the ownership of the files.

The format of switches varies widely between operating systems. Under the OpenVMS operating system, switches are entered in the form command/switch_1/switch_2/switch_3=value "etc." The form /switch=value is used to provide an argument to the switch; for example, /user=john might specify that only files owned by the user "john" should be displayed.

MS-DOS and related operating systems typically use single-letter switches, for example dir/w/p/a:s. In this case, the : character serves the same purpose as = above.

Traditionally, MS-DOS is similar to the Unix operating system; switches are single letters or digits, and introduced via a - (hyphen); "e.g." ls -l -F -a -1. When options are given in this form (a dash and then a letter or word), they are more often called "flags" - as in compiler flags. Multiple flags may be combined into one, so the previous command could be rewritten ls -lFa. However, with the increasingly widespread use of software from the GNU project, particularly in the Linux operating system, GNU's long options are also widely used. Long options are introduced via --, and are typically whole words. For example, ls --long --classify --all. Arguments to long options are provided with =, as ls --block-size=1024. Some Unix programs use long options with single dashes, for example MPlayer as in mplayer -nosound.

GNU also uses -- to terminate option lists. For example, an attempt to delete a file called -file1 by using rm -file1 may produce an error, since rm may interpret -file1 as a command line switch. Using rm -- -file1 removes ambiguity.


Wikimedia Foundation. 2010.

Look at other dictionaries:

  • command-line argument —    A parameter that alters the default mode of a command. In many operating systems, a commandline argument is one or more letters or numbers preceded by the / (slash) character. In Unix, a command line argument may be called an option or a flag… …   Dictionary of networking

  • Command-line argument parsing — Different Command line argument parsing methods are used by different programming languages to parse command line arguments. Contents 1 Programming languages 1.1 C 1.2 Java 1.3 Perl …   Wikipedia

  • Command-line interface — Screenshot of a sample Bash session. GNOME Terminal 3, Fedora 15 …   Wikipedia

  • Command-line interpreter — A command line interpreter (also command line shell, command language interpreter) is a computer program that reads lines of text entered by a user and interprets them in the context of a given operating system or programming language. Command… …   Wikipedia

  • In the Beginning... was the Command Line — In the Beginning...was the Command Line is a lengthy essay by Neal Stephenson which was originally published online in 1999 and later made available in book form (November 1999, ISBN 0380815931). The essay is a commentary on why the proprietary… …   Wikipedia

  • Argument (disambiguation) — In general parlance, an argument is a discussion involving conflicting points of view. General types of argument * Argument, a demonstration of a proof, or using logical reasoning for persuasion * Argument form, the logical structure of an… …   Wikipedia

  • Command (computing) — 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. Specifically …   Wikipedia

  • Print (command) — In computing, print is a command in the command line interpreters (shells) of DOS, OS/2 and Microsoft Windows. It is used to add a file to the print queue. It is equivalent to the Unix command lpr.The command was introduced in MS DOS version 2.… …   Wikipedia

  • choice (command) — In computing, CHOICE is a DOS command that allows for batch files to prompt the user to select one item from a set of single character choices. It was introduced as an external command (with filenames CHOICE.COM or CHOICE.EXE) with MS DOS 6.0,[1] …   Wikipedia

  • Help (command) — In computing, help is a command in various command line shells such as COMMAND.COM, cmd.exe, 4DOS/4NT, Windows PowerShell, Python and GNU Octave. It provides online information about available commands and the shell environment. It is analogous… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”