5

Why do Command Line flags like --recursive have two dashes instead of just -recursive?

I know that the shortened version is just -r.

Why do these flags use two hyphens rather than one hyphen?

Is there a maximum number of characters that a flag with one dash can have before it requires two dashes?

pkamb
  • 4,775
  • 6
  • 40
  • 52

2 Answers2

5

The issue is that you can say things like ls -laR; it’s equivalent to ls -l -a -R.  So -recursive would be interpreted as -r -e -c -u -r -s -i -v -e.

1

There's no exact rule to use single or double dash as an option to a program. If one decided to handle options on one's own one can implement whatever one want. But if programmer isn't looking for a PITA and want the program to use common, well recognizable way then one would use standard function(s) getopt/getopt_long that handle long options (long string as you asked) as double dashed an short options(single character) prefixed with single dash. The function getopt is part of <unistd.h> in C language. The same function can be used on Unix based systems in standard shells man getopt 1 that utilize parsing single and double dashed (long) options.

Is there a maximum number of characters that a flag with one dash can have before it requires two dashes?

If one uses function described above then short options can have only one single character.

Alex
  • 6,375