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>]
2
  • 1
    also unix.stackexchange.com/a/16339/117549 Commented Jan 5, 2016 at 17:52
  • @powtac This question may be a duplicate, but it was the first hit google gave when searching for an answer, so I'm glad it was there. Commented Jun 26, 2019 at 4:52

1 Answer 1

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.

1
  • 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. Commented Jan 5, 2016 at 18:14

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.