These typically define an option as an argument beginning with a hyphen ( -) and some options may use proceeding arguments as its parameters. You can either roll your own, for exampe a shell (such as bash) script can use provided getopts or getopt commands. How this is done is implementation-specific. Other languages have similar ways to access them (commonly through an array with a name like argv).Īrguments may be interpreted as options if you wish. In a shell script you access arguments using the special variables $0. At the lowest level, we have argument and everything is an argument, including the (filesystem path to the) command itself. The man page for a typical Unix command often uses the terms argument, option and parameter. Note also that optional variable assignments and redirections, despite being processed by the shell for tilde expansion, parameter expansion, command substitution, arithmetic expansion, and quote removal like other command line parameters are not taken into account in my reply because they have disappeared when the command is actually called and passed its arguments.ġ I should have written usually documented because of course, undocumented options are still options.Ģ The double dash feature need to be implemented by the program though. Note that some commands like test, tar, dd and find have more complex argument parsing syntax than the ones described previously and can have some or all of their arguments parsed as expressions, operands, keys and similar command specific components. $ git -git-dir=a.git -work-tree=b -C c status -s Unlike parameters, the list of possible subcommands is hardcoded in the command itself. With them, you might have global options preceeding the subcommand, and subcommand specific options that follow the subcommand. there are subcommands, also known as functions / (low-level) commands, which are used with "metacommands" that embed multiple separate commands, like busybox, git, apt-get, openssl, and the likes. $foo, $bar.) and special character ones (e.g. This includes positional parameters (e.g. $ ls -la /tmp /var/tmpĪ shell parameter is anything that store a value in the context of the shell. Should you need to pass a parameter that looks like an option but shouldn't be interpreted as such, you can separate it from the beginning of the command line with a double dash: - 2. Unlike options, whose possible values are hard coded in programs, parameters are usually not, so the user is free to use whatever string suits his/her needs. in -o file, file is the parameter of the -o option. $ ls -la /tmp /var/tmpĪ parameter is an argument that provides information to either the command or one of its options, e.g. There are however some commands with paradoxical "mandatory options". As their name suggests, options are usually optional. There are also long options like -verbose (see also Using getopts to process long and short command line options). lv are two options combined in a single argument. $ ls -la /tmp /var/tmpĪn option is a documented 1 type of argument modifying the behavior of a command, e.g. These arguments are sometimes called positional parameters. Argument 0 is (normally) the command name, argument 1, the first element following the command, and so on. A command is split into an array of strings named arguments.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |