3 ms·
The --long-option thing is a GNU thing: https://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html https://www.gnu.org/software/libc/manual/html_no
by tom_ 3y ago
The --long-option thing is a GNU thing: https://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html https://www.gnu.org/software/libc/manual/html_node/Argument-...
- swozey 3y agoI've never even thought about this. I think this is kind of strange > An option and its argument may or may not appear as separate tokens. (In other words, the whitespace separating them is optional.) Thus, -o foo and -ofoo are equivalent. Thanks this is super helpful I never knew this was a GNU thing.
- yjftsjthsd-h 3y agoNote that there's an opposite convention that I think originated with the BSDs, where -ofoo is equivalent to -o -f -o -o
- cb321 3y agoThat only holds when 'o' and 'f' are both boolean "flags" taking no arguments. If 'f' is more like --file=x then it takes an argument. More specifically, getopt(3) in POSIX lets programmers very this by giving a format string. "o:f" would make your example parse as "-o" "foo" while "of:" would make it parse as "-o" "-f" "oo" and an "of" format would make it parse as you describe, "-o" "-f" "-o" "-o". ( darnir mentioned parts of this above: https://news.ycombinator.com/item?id=38968612 https://news.ycombinator.com/item?id=38968612 using the term "single character flags" to indicate no argument. ) Also, while --long-option is GNU, gcc which is perhaps the aboriginal GNU command-line utility uses single dash as in, e.g. `gcc -pipe`, though it also accepts `gcc --help`. CL syntax remains quite varied in the wild.