Jump to content

Command-line argument: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Line 40: Line 40:
[[MS-DOS]] and related operating systems typically use single-letter switches, for example <tt>[[dir (command)|dir]] /w /p /a:s</tt>. In this case, the <tt>:</tt> character serves the same purpose as <tt>=</tt> above.
[[MS-DOS]] and related operating systems typically use single-letter switches, for example <tt>[[dir (command)|dir]] /w /p /a:s</tt>. In this case, the <tt>:</tt> character serves the same purpose as <tt>=</tt> above.


Traditionally, MS-DOS is similar to the [[Unix]] operating system; switches are single letters or digits, and introduced via a <tt>-</tt> (hyphen); ''e.g.'' <tt>ls -F -a -1</tt>. 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 <tt>ls -Fa1</tt>. 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.
Traditionally, MS-DOS is similar to the [[Unix]] operating system; switches are single letters or digits, and introduced via a <tt>-</tt> (hyphen); ''e.g.'' <tt>ls -F -a -1</tt>. 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 <tt>ls -Fa1</tt>. 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. BY CHETAN


== See also ==
== See also ==

Revision as of 06:51, 18 January 2011

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 option or simply option (also known as a command line parameter, flag, or a switch) is an indication by a user that a computer program should change its default output.

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 option /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.

In OpenVMS

Under the OpenVMS operating system, options (traditionally: switches) are entered in the form command/option_1/option_2/option_3=value etc. The form /option=value is used to provide an argument to the option; for example, /user=john might specify that only files owned by the user "john" should be displayed.

In Cisco IOS

IP ADDRESS 123.232.232.222 255.255.0.0

The 123.232.232.222 and 255.255.0.0 parts are arguments.

In UNIX and Linux

In traditional UNIX, options typically consist of a single letter introduced by - and possibly followed by an argument.

This turned out to be a limiting factor in complex programs requiring many options, so in GNU software the concept of long options was added. 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, or as a separate argument as ls --block-size 1024. Some Unix programs use long options with single dashes, for example MPlayer as in mplayer -nosound.

GNU/Linux 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.

Also note that some Linux command line options use no parameter prefix dashes at all, e.g. yum.

In MS-DOS

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 -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 -Fa1. 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. BY CHETAN

See also