3

I'm creating a CLI utility which is aimed at *nix OS:es. Let's call it 'Super CLI Project'. Looking at the latest POSIX Issue 7, 2018 edition - https://pubs.opengroup.org/onlinepubs/9699919799/ - Utility Conventions - The section shows an example with underscores like this ->

utility_name[-a]... 

which I could interpret as that my util should be named super_cli_project, by convention (with underscores as separator). However, POSIX does not say this explicitly.

A quick 'ls' in my /usr/bin/ shows that most utils in my OS (Ubuntu) that consists of several words uses a hyphen instead of an underscore. That implies that my util should be named 'super-cli-project' instead.

So, what is really the preferred naming convention here?

Note: There are a few discussions regarding FILENAMES in general for this topic - but not for the naming conventions of *nix CLI utils themselves.

2
  • 2
    I do not think there is rule. And its a case of personal preference. Commented Jul 16, 2024 at 19:14
  • 2
    if you read further, under "12.2 Utility Syntax Guidelines", the guidelines seem to say neither hyphens or underscores are recommended: "Guideline 2: Utility names should include lowercase letters (the lower character classification) and digits only from the portable character set." (The word order is a bit odd, but I'm taking that to mean "should include only these".) I'd ignore that and use hyphens if it seemed useful. Hyphens, because I find them less ugly than underscores. In many programming languages, hyphens clash with the syntax, but that's not the case for utility names (filenames) Commented Jul 16, 2024 at 19:43

1 Answer 1

5

I’m not aware of relevant rules or even recommendations. A quick look at systems I have handy shows that hyphens are more common than underscores.

Hyphens might be easier to type on some keyboard layouts, in particular on QWERTY — hyphen is unshifted, underscore is shifted. Commands using hyphens will therefore be easier to type.

(One factor contributing to the use of hyphens is the “plugin pattern”. Commands supporting plugins or extensions, such as git or kubectl, use hyphens. man-db’s man has explicit support for that: man git stash looks for a git-stash page; that works with underscores too so it’s not an argument in favour of one over the other.)

2
  • the plugin convention & mandb support argument is a good one! But: man dd rescue opens dd_rescue(1) just as well. Commented Jul 16, 2024 at 21:18
  • 2
    Another small reason to prefer hyphens: the cursor might be an underscore (usual ones are a bar, box or underscore), and it will be slightly less confusing when the cursor is over an actual typed underscore Commented Jul 17, 2024 at 0:59

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.