2

Scripts on command line offer a wide range of parameters types. Often parameters can be passed to the script via "--[parameter]" or "-[parameter]". But what is the difference? Why do some parameters have a double "-" and some only a single "-" prefix? Is there a convention of a technical reason behind this?

Example of possible git parameters. (See --exec-path[=<path>] vs. -c name=value)

git [--version] [--help] [-C <path>] [-c name=value]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]
powtac
  • 121

1 Answers1

1

It depends on the language of the written application. For example in bash you can parse short args (-) with both getopt and getopts and long (--) ones with getopt only.

getopts is a bash function, getopt is an separate program. So for maximal portability of your bash scripts, you have to use getopts and short notation.

For other languages you can refer to the "parsing arguments" section of the appropriate documentation.

derobert
  • 109,670
user1700494
  • 2,202
  • 1
    The OP's example is git, which is largely written in C. And it's only one command—with both short and long options. – derobert Jan 05 '16 at 18:14