48

Should the name of command line options for a program in a POSIX-style operating system be underscore-style, like

--cure_world_hunger

or maybe some other style?

--cureworldhunger
--cure-world-hunger
--cureWorldHunger

What's most common? What's better style? What's more Bash-friendly (if such a thing exist)?

Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622

3 Answers3

58

Underscore is not a good idea, sometimes it gets "eaten" by a terminal border and thus look like a space.

The easiest to read, and most standard way is to use a dash:

--cure-world-hunger
Niko
  • 6,133
  • 2
  • 37
  • 49
44

Always hyphens! Let's get a reputed reference: the Gnu style guide:

GNU adds long options to these conventions. Long options consist of ‘--’ followed by a name made of alphanumeric characters and dashes. Option names are typically one to three words long, with hyphens to separate words. Users can abbreviate the option names as long as the abbreviations are unique.

Another problem with underscores is that if the documentation is linked in a HTML document, the link underline will hide the underscore and will confuse the user.

neves
  • 33,186
  • 27
  • 159
  • 192
  • 10
    @neves - Thank you for this useful answer. Please don't be discouraged, and continue to provide answers that include references to primary sources like this one. IMO this is the perfect antidote to a question that might otherwise be opinion-based. – user200783 Sep 11 '19 at 02:16
  • 5
    @neves - Yes, this should be the accepted answer for not being opinion based and for citing primary sources. Great answer! – rafaelbattesti Sep 17 '19 at 22:13
2

The double dash prefix is a GNU convention I believe. Check out getopt_long(3) man page on the GNU/Linux Operating System.

Sean A.O. Harney
  • 23,901
  • 4
  • 30
  • 30