command line - Why do some Linux programs specify long form and shorthand arguments? -
whenever through documentation , man-pages, notice linux programs have 2 types of arguments, , genuine interest have in finding out...
- one seems full argument name (long form).
- and 1 seems shorthand.
take grep example. if run grep --help disclaimer: not question grep in particular. i've seen in many other tools.
regexp selection , interpretation: -e, --extended-regexp pattern extended regular expression -f, --fixed-strings pattern set of newline-separated strings -g, --basic-regexp pattern basic regular expression -p, --perl-regexp pattern perl regular expression -e, --regexp=pattern use pattern regular expression -f, --file=file obtain pattern file -i, --ignore-case ignore case distinctions -w, --word-regexp force pattern match whole words -x, --line-regexp force pattern match whole lines -z, --null-data data line ends in 0 byte, not newline one can see there 2 types of arguments. shorthand, , full argument name.
another thing note, if specify shorthand of these arguments, separated space, when using full argument, seems separated = sign. e.g: grep --file=file vs grep -f file
- what purpose of having 2 different types of arguments same thing?
- are able use
grep --file fileinstead ofgrep --file=file? - to question 2, if answer "because how programmed it," question why program way? there reason can't use
grep --file file? - is there convention should follow?
- does leading
-ingrep *-*-fileplay important part in something?
i'd appreciate solid answer on can understand why programmers way!
thanks!
in addition other answers, long , short options handled argp & getopt_long (from glibc), , several other options handling functions (e.g. in qt or gtk).
and gnu coding standards recommend them, , --help , --version.
some (rarely useful) command options have long form (e.g. --time-style gnu ls).
btw, if write command line software linux either free software or distributed (perhaps sold), please accept --help option: becoming common convention. hate few programs not following it!
Comments
Post a Comment