I’m aware that the general convention is that short flags (or single dash “-“) is followed by a single character, and long flags (or double dash “–“) is followed by multiple characters (usually an English word). Also, sometimes multiple short flags can be written like this as shorthand (“-l -c” as “-lc”).
However, is this also valid “–c”? It seems to be breaking the aforementioned convention but is it fine as long is it’s a unique flag identifier?
Tried searching the web but wasn’t able to find any results on this.
Advertisement
Answer
Yes, as a general rule, neither your shell nor your kernel cares about the format of the arguments you pass to your command, as long as the program you’re writing expects that format.
However, if by “can” you mean “does that respect the POSIX conventions of command arguments”, then you should look at the Utility conventions part of the POSIX standard. In the last published version, there is no particular restriction against what you want here, therefore you should be fine.
That said, when you write programs for other people, try to apply the Principle of least astonishment. People usually expect single letter commands to be preceded by a -
, so it is a good practice to follow the de-facto conventions when possible.