14 ms·
Unix command line conventions over time
- amtamt 5y agoWhat is the getopt equivalent for sub command handling? Or get opt can parse subcommads too?
- teddyh 5y agoYou probably want argp_parse(): https://www.gnu.org/software/libc/manual/html_mono/libc.html#Argp https://www.gnu.org/software/libc/manual/html_mono/libc.html... See especially getsubopt(): https://www.gnu.org/software/libc/manual/html_mono/libc.html#Suboptions https://www.gnu.org/software/libc/manual/html_mono/libc.html...
- kzrdude 5y agoThe GNU conventions are terribly convenient. If we were redesigning it from scratch, I'd like to keep all of them except for removing duplicated functionality. One of --long x and --long=x have to go, and that means we only can keep --long=x. And so on.
- conaclos 5y ago> that means we only can keep --long=x Just wondering: why `--long=x` over `--long x`?
- grose 5y ago`--long x` is potentially ambiguous. `x` could be referring to a file if `--long` doesn't take any options, so parsing it correctly depends on this knowledge. The equals sign removes this ambiguity.
- kzrdude 5y ago--long=x supports the simultaneous --color and --color=auto usecase, i.e the value is optional. Without = it's ambiguous.
- deleted 5y ago[deleted]
- jolmg 5y agoIt also has the advantage that it works with brace expansion to specify multiple values. --long={foo,bar} becomes --long=foo --long=bar
- conaclos 5y agoWith bash/zsh the auto-completion seems missing for unknown options. While `--key file` supports auto-completion since file is just another parameter.
- kzrdude 5y agoThanks for teaching something useful!
- conaclos 5y agoActually you can expand any pattern: --option{X,Y} -> --optionX --optionY --option:{X,Y} -> --option:X --option:Y ...
- mort96 5y agoI disagree with getting rid of `--long x`. It's really common to build command argvs programmatically, where you have a string representing some option (such as a file path), and you need to pass that as a long option. With `--long x`, you can do like: char *argv[] = {"my-program", "--config-file", config_file, NULL}; run_command(argv); With only `--config-file=x`, you would have to allocate memory for the option: char *config_file_opt = asprintf("--config-file=%s", config_file); char *argv[] = {"my-program", config_file_opt, NULL}; run_command(argv); free(config_file_opt); And it becomes even more hairy if you A) want to avoid heap allocation in most cases or B) want to use standard functions rather than asprintf. You'd have to do something like this: char config_file_opt_buf[1024]; char *config_file_opt; size_t config_file_opt_len = snprintf(config_file_opt_buf, sizeof(config_file_opt_buf), "--config-file=%s", config_file); if (config_file_opt_len >= sizeof(config_file_opt_buf)) { config_file_opt = malloc(config_file_opt_len); snprintf(config_file_opt, config_file_opt_len, "--config-file=%s", config_file); } else { config_file_opt = config_file_opt_buf; } char *argv[] = {"my-program", config_file_opt, NULL}; run_command(argv); if (config_file_opt != config_file_opt_buf) { free(config_file_opt); } And even that ignores any kind of error checking of snprintf or malloc which may fail. I also wouldn't even be comfortable assuming the code I just wrote is correct, without thinking long and hard about it and reading standards/documentation thoroughly. Whereas the first example is so simple it's obviously correct. I think we should keep `--long x`. If anything, `--long=x` is the one which should go. There will always be ambiguity; the meaning of something like `-ab` also depends on whether `-a` takes an argument or not. Really though, I think there are enough situations where `--long=x` is useful that I think keeping both versions makes sense.
- jbverschoor 5y agoIf all of this matters so much, don’t use an (interactive) shell.
- mort96 5y agoWe're not talking about the shell, we're talking about the options parser. Nothing in my examples invokes any shell.
- inopinatus 5y agoStill waiting for su —-with-wheel-group
- euroderf 5y agoI come not to bury wheel, but to praise it.
- Maursault 5y agoAn industry big wheel, a wheel man with nice wheels, put shoulder to the wheel to put wheels in motion spinning wheels to reinvent the wheel before the wheels came off the wagon and squeaky wheel gets the grease. My name is Jonas. I'm carrying the wheel.
- euroderf 5y agoI confess that back in the day, whenever I tried to grok a man page or manual page about wheel, it was basically incomprehensible.
- deleted 5y ago[deleted]
- megous 5y agoSometimes I'm glad for public interface ossification. :)
- sph 5y agoI am annoyed go's flags package did not respect the GNU convention for options, which I agree is the best.
- layer8 5y agoI’m curious why they introduced the ‘=‘ variant at all. Maybe they thought it would be clearer for human readers?
- nohackeratall 5y agoAnd then you have ImageMagick where the order of flags and options is a science by itself.
- wchar_t 5y agoIndeed, I passionately hate programs where the order of the options and files/arguments matter just as much as the options themselves.
- zvr 5y agoGiven that ImageMagick can describe a sequence of operations (much like commands piped together), the order is obviously significant. The exact same holds for ffmpeg command-line.
- loudmax 5y agoThe `find` command is extremely useful, but user-friendly, it is not. $ find -type f Data/ find: paths must precede expression: `Data/' find: possible unquoted pattern after predicate `-type'? sigh
- jbverschoor 5y agoWell magick is more a single live scripting language with multiple paths. While it works, I think it’s the wrong tool for the job
- nocman 5y agoSo you are saying Imagemagick is the wrong tool for any job then? (I ask this because the OP didn't reference any particular task). I would disagree with that. Like many media-related command line tools, it does a lot and therefore has a fairly involved command line interface, but I have found it very useful over the years for processing multiple images (and sometimes even just individual ones).
- sph 5y agoAlso ps. Everyone uses their own incantation and never strays from it. I use `ps aux` and used to use `ps -def` on Solaris. Some options require a dash, some don’t, it’s such a confusing CLI I never bothered to learn more. EDIT: also why is `ps` default output so useless? With no arguments it only prints a couple processes and that's it. I have no idea what it's supposed to show me. Talk about bad UX.
- debdut 5y ago> --mail=ADDR > The --email bit is a joke. what's the context of the joke?
- kwijybo 5y agoZawinski's Law of Software Envelopment, also known as Zawinski's Law, states: Every program attempts to expand until it can read mail.
- nonrandomstring 5y agoCaught me out! I assumed it meant to send the output of the command as mail. That's vaguely useful instead of piping to a cmdline MUA. I couldn't believe I'd been missing this for 30 years and so I tried it on few things like ps aux --mail=me@domain error: unknown gnu long option Looked in my inbox. Nothing. Then I got to the bottom of the page for the punchline. grrrr
- sph 5y agoAlso the idea that GNU tools are bloated.
- ggm 5y agoI don't think this is entirely wrong, but it's drawing a bit of a long bow. The getopt wars on Usenet were interesting, shar files flew around before we settled on gnu's take on things. I think distinct shell commands are good. MH is my go to instance of doing this right (it's still under active development)
- pseudostem 5y agoUnix history is always fascinating. >None of this explains dd. This one really made me think. I have never thought about dd before. Although I have wondered about other commands. Perhaps the author should also have added some command options not requiring a minus prefix, e.g. tar, ps. The manpage [0] reads: In the first (legacy) form, all option flags except for -C and -I must be contained within the first argument to tar and must not be prefixed by a hyphen (`-'). Option arguments, if any, are processed as subsequent arguments to tar and are processed in the order in which their corresponding option flags have been presented on the command line. In the second and preferred form, option flags may be given in any order and are immediately followed by their corresponding option argument values. [0]: http://man.openbsd.org/tar http://man.openbsd.org/tar
- dredmorbius 5y agodd is a mainframe command, and its syntax follows the JCL conventions used there. https://www.ibm.com/docs/en/zos-basic-skills?topic=concepts-jcl-statements-what-does-dd-statement-do https://www.ibm.com/docs/en/zos-basic-skills?topic=concepts-...
- smcameron 5y agoHuh. I'd always kind of guessed that dd used if=input-file of=output-file as a way to sort of prevent the use of shell globbing and to not rely on the order of arguments (as cp does) since dd as it is often used can be a bit dangerous (I often found myself using it with disk device files) and you want to be extra careful in specifying the input and especially the output files. Edit: wikipedia agrees with your IBM origin story https://en.wikipedia.org/wiki/Dd_(Unix)#History https://en.wikipedia.org/wiki/Dd_(Unix)#History
- dredmorbius 5y agoThe syntax is common to most JCL ("job control language") commands. I'd say "all", though there are probably exceptions. For some reason, this seems to be vanishingly scarce knowledge in Linux / Unix circles. There was a time in my life I knew how to spell JCL....
- oaiey 5y ago"Nothing of that explains did"... Made my day
- jiehong 5y agoAnd then there is also the case of CLIs that aren’t written in C: they don’t get the benefits of a unified getopts lib. One oddity not explained is tar allowing multi options crammed together without any dash, that nobody can ever remember (eg. tar xvf archive.tar)
- teddyh 5y agoOr ps, with its BSD and SysV variants. On Linux, the most widely used version of ps uses BSD semantics when using options without a dash, and SysV semantics for dashed options. Thus, both BSD “ps aux” and SysV “ps -fel” work.
- LeoPanthera 5y ago> One oddity not explained is tar allowing multi options crammed together without any dash, that nobody can ever remember (eg. tar xvf archive.tar) This is a BSDism, and it's deprecated even there. bsdtar allows it for compatibility with old scripts. GNUtar has long-switches for all options, which makes it considerably easier to use and understand, for example: gtar --create --file etc.tar --verbose /etc
- nsajko 5y ago> This is a BSDism No, it was like that when Tar was first introduced, as part of Seventh Edition Unix: https://man.cat-v.org/unix_7th/1/tar https://man.cat-v.org/unix_7th/1/tar https://en.wikipedia.org/wiki/Tar_(computing) https://en.wikipedia.org/wiki/Tar_(computing)
- eesmith 5y agoSee also "tap" from v1, to "manipulate DECtape", described at http://www.bitsavers.org/pdf/bellLabs/unix/UNIX_ProgrammersManual_Nov71.pdf http://www.bitsavers.org/pdf/bellLabs/unix/UNIX_ProgrammersM... , p94 of the pdf: > tap [key] [name ...] > The function portion of the key is specified by one of the following letters ... For example, "x" to extract. > The following characters may be used in addition to the letter which selects the function desired For example, "v" for verbose.
- teddyh 5y ago> Initially, GNU used the plus (+) to indicate a long option, but quickly changed to a double dash (--). IIRC, they liked the plus, but changed to use the double dash to be POSIX compatible (which presumably requires options to be preceded by a dash).
- jolmg 5y agoI like the use of + to mean the opposite of single dash short options, like with shell options, e.g. `set -e` vs `set +e`. For long options, there's the convention of `--no-foo` meaning the opposite of `--foo`, but `+e` hasn't really caught on for short options besides the shell ones. Being able to negate options, letting the last one win, is useful to be able to define default options in aliases. For example, it might be useful to be able to do this: $ alias less='less -X' $ less +X foo.txt or $ alias grep='grep -n' $ grep +nH -r foo *
- mort96 5y agoI find it really confusing when `+x` is used to mean the opposite of `-x`. Usually, the `-x` option means "enable something", which is fine when you think of the "-" as a dash, but introducing `+x` encourages you to think of them as minus and plus; suddenly, in your command's language, "minus x" means "enable x" and "plus x" means "disable x", which makes very little sense. The set command is a great example, "minus e" means "enable error checking" and "plus e" means "disable error checking". That doesn't make sense, that's not what minus and plus means.
- euroderf 5y agoAlso "nice".
- yourad_io 5y agoConsider the semantics: niceness (relinquishes resources) as the opposite of meanness (demands resource) in a multi user system > This is why the nice number is usually called niceness: a job with a high niceness is very kind to the users of your system (i.e., it runs at low priority), while a job with little niceness hogs the CPU. The term "niceness" is awkward, like the priority system itself. Unfortunately, it's the only term that is both accurate (nice numbers are used to compute the priorities but are not the priorities themselves) and avoids horrible circumlocutions ("increasing the priority means lowering the priority..."). Jerry Peek et al. in Unix Power Tools (O'Reilly, 2007, p. 507) via https://stackoverflow.com/questions/14067128/why-are-niceness-values-inversely-related-to-process-priority https://stackoverflow.com/questions/14067128/why-are-nicenes...
- theden 5y agoThere are alternatives to dd like ddrescue (https://wiki.archlinux.org/title/disk_cloning#Block-level_cloning https://wiki.archlinux.org/title/disk_cloning#Block-level_cl...), but given it's standard on all *nix machines it's hard to avoid, just need to be extra careful before executing. There are also wrappers for dd, like ddi (https://github.com/tralph3/ddi https://github.com/tralph3/ddi) for extra safety
- conaclos 5y agoI pretty like the consistency of esbuild CLI [1]. It has three kinds of options: 1. no-valued option: --example 2. single-valued option: --key=value 3. multi-valued option: --elements:1st --elements:2nd Short options are ruled out, although it accepts the short option -h for discoverability. I particularly like the repeated option pattern for multi-valued options. This avoids ambiguities such as: cli --elements 1st 2nd arg Yes, the ambiguity may be removed by using doubled dashes. However, this is error-prone. I often wondering whether a more familiar syntax for the second and third kinds could be adopted. For instance: --key value --elements 1st --elements 2nd [1] https://github.com/evanw/esbuild https://github.com/evanw/esbuild
- bbkane 5y agoThis is largely what the Azure CLI does. It simplifies even further by eliminating the no-value option. Instead, you pass "true" or "false" as the value ( --example true ). It's a little more verbose but very easy to parse/write/generate. I like this convention so much I stole it for my homemade Golang CLI parsing library https://github.com/bbkane/warg/ https://github.com/bbkane/warg/ .
- bluenose69 5y ago> we could introduce a completely new syntax that is systematic, easy to remember Is it really difficult to learn that e.g. "rm" stands for "remove"? I've known very few people who found it difficult to learn the key things very quickly. And not having to type (and spell) full words is a relief. (I know a shell can take care of spelling, but not all unix commands are entered interactively.) Still, the article is interesting, and worth reading.
- morelish 5y agoTbh I’ve found powershell approach better and also more verbose. Powershells commands are all named in the same way, with built-in support to make finding commands straightforward. Though it takes a while to get used to it. Explorability is better IMO with an approach like powershell. The downside is even though you can setup aliases, it still seems like powershell scripts are longer to input that bash and sometimes not as powerful.
- bzxcvbn 5y agoPowershell defines tons of aliases to mimic bash, eg rm is an alias for remove-item, ls for get-childitems, cat for get-content, etc. What I like about Powershell is that arguments gets aliases too, for example -cf is the standard alias for -confirm.
- ElectricalUnion 5y agoThe cool part about those aliases is that invoking Get-Help on them (say, Get-Help ls) will show you the relevant documentation of the non-aliased full commandlet name.
- justsomehnguy 5y agoThe best thing with parameters in PS is what you don't need to write parameter name fully, and it is supported everywhere, while only some *nix tools support it (most notably 'ip')
- bbkane 5y ago
- teddyh 5y ago> GNU also added standard options: almost every GNU program supports the options --help, --version GNU keeps a list of them, so that anyone implementing a similar functionality should use the same option if it already exists: https://www.gnu.org/prep/standards/standards.html#Option-Table https://www.gnu.org/prep/standards/standards.html#Option-Tab...
- teddyh 5y ago> Initially, GNU used the plus (+) to indicate a long option Some tools still use +options, like dig(1).
- conaclos 5y agoAnd others use option -long such as ffmpeg.
- brabel 5y agoAnd Java with the infamous `-version` (only after JDK11 I think it started recognizing also `--version`) and `-cp` meaning `--classpath`, not `-c -p`!
- lifthrasiir 5y agoAlso in some cases both -options and +options exist, where +options do the inverse of -options (e.g. dash; I think the old Perl 6 also did the same thing for sub MAIN, though it's now -/options) or a subtle but useful variation of -options (e.g. ImageMagick).
- nsajko 5y agoDash just implements the behavior specified by POSIX/SUS.
- lifthrasiir 5y agoIn hindsight, indeed! They just go straight into `set`.
- eesmith 5y agoOr "tail", where "tail -12" is the last 12 lines and "tail +12" is everything after the first 12 lines.
- MontyCarloHall 5y agoThe worst offender in this regard is bash’s `set` command. For example, `set -e` enables the `e` option (exit script immediately upon seeing a nonzero exit code). Guess how to disable it? Yup, `set +e`
- teddyh 5y ago> I believe the oldest program that uses subcommand is the version control system SCCS, from 1972 IIUC, other non-Unix operating systems commonly used the subcommand style for normal interactive use; it was the style used by the normal command shell, and all commands in those operating systems therefore followed this style. The operating system (or its shell) was responsible for enabling easy use of this style by adding completion support (commonly using the ESC key, IIRC). This older style can still today be seen in Unix tools like ftp and telnet, which uses this style for its internal command line interface. Another tool using this style, which many might be familiar with, is the multi-platform Kermit. Unix therefore has been rather late in adopting this style, first in gradually adopting tools which uses the subcommand style (ip, git, etc.), and later with support in shells for programmable completion support where a program can optionally register completion hooks for the user shell to use, making it finally come up to the level of those older operating systems.
- ducktective 5y agoSpeaking of CLI option/argument handling for shell scripts, I use getopts for simple scripts which have few switches and manual loop when I want to support long options. 1- short: http://mywiki.wooledge.org/BashFAQ/035#getopts http://mywiki.wooledge.org/BashFAQ/035#getopts 2- long: http://mywiki.wooledge.org/BashFAQ/035#Manual_loop http://mywiki.wooledge.org/BashFAQ/035#Manual_loop I don't support `--option=` mode. I don't support giving options after arguments. I prepend info and errors with braces like : `[TAG] message` and print them to STDERR. Opinions?
- aap_ 5y agoThe chronology is wrong. dash-options came before pipes. The first edition already has them while pipes came in the third edition.
- eesmith 5y agoAs supporting evidence, the Unix Manual from 1971, http://www.bitsavers.org/pdf/bellLabs/unix/UNIX_ProgrammersManual_Nov71.pdf http://www.bitsavers.org/pdf/bellLabs/unix/UNIX_ProgrammersM... contains synopses like: du [-s] [-a] [name ...] ld [-usaol] name ] ls [-ltasd] name ... pr [-lcm] name
- Maursault 5y agoWow, that's the actual manual, first edition man pages.
- Purplish5583 5y agoInteresting. When did redirections got added?
- gpvos 5y agoVery early, before the pipes.
- codeulike 5y agoI thought Powershell syntax was needlessly confusing until I started writing bash scripts, now I see that ps wasn't so bad. But I accept why linux command line is the way it is - its a shark, not a dinosaur
- protomikron 5y agoInteresting is also find. It took me some time to accept that the directory must come first. E.g. find /path/to/dir -type f works, while find -type f /path/to/dir does not.
- tomxor 5y agoYup, always seems to take a bit more conscious effort to remember that detail for find.
- mort96 5y agoProbably helps to think of find as its own weird pipeline rather than a command with options. The first element of the pipeline is the directory(/directories), then `-type f` filters out all the non-files, then `-name '*.txt'` filters out everything which doesn't end in ".txt", etc. That also helps to remember why `-maxdepth` has to be right after the directory; it affects which files even become part of the pipeline, it doesn't make sense as a pipeline element. The clearest proof that it's a pipeline is probably how it interacts with `-exec`: `find . -type d -exec echo {} \;` will print only directories, while `find . -exec echo {} \; -type d` will print both files and directories. Regardless though, I sure wish they would let you specify the directories at the end.
- yourad_io 5y agoVery insightful, I never realized this. Thank you
- chubot 5y agoI wrote a post about how to understand find syntax: find and test: How To Read And Write Them https://www.oilshell.org/blog/2021/04/find-test.html https://www.oilshell.org/blog/2021/04/find-test.html tl;dr The args AFTER the root dir args form a boolean expression language -- I call it the "I'm too lazy to write a lexer" pattern find /tmp -type -f -a -name 'foo*' test is the same way, e.g. test -f /tmp -a -f /bin
- michaelcampbell 5y ago
- bfrankline 5y agoI was at Bell during the options “debate.” I think something that this otherwise wonderful article misses is that some believed that commands were never intended to be the only way to use the system as the shell was intended to be just one of the many user interfaces that Research Unix would provide. From that perspective, it was entirely reasonable to believe that if a command was so complex that it needed options than it was likely more appropriate for one of the other user interfaces. I believe this is unfortunately now understood by some as it shouldn’t exist. However, because of the seemingly instantaneous popularity of the shell and pipelining text it became synonymous with Unix. It’s a shame because McIlroy had a lot of interesting ideas around pipelining audio and graphics that, as far as I know, never materialized.
- Tijdreiziger 5y agoInteresting, any chance you could expand on these 'other user interfaces'? I'm not really familiar with Unix itself, but I've always considered Linux a shell-first OS (as opposed to Windows (NT), which I consider a GUI-first OS).
- imwillofficial 5y agoA shell is just how you interact with the underlying system. The gui is also a shell. Confusing I know!
- daptaq 5y agoI like to see it this way: A shell /wraps/ the kernel. You cannot issue system calls directly, but a program that handles user input generically (and ideally dynamically), can do this for you. A desktop environment, Emacs, and to an increasing degree web browsers are all different "shells".
- imwillofficial 5y agoLike valence shells on atoms. I dig it
- kevin_thibedeau 5y agoGCC doesn't actually follow GNU conventions since it has both single hyphen and double hyphen long options.
- mort96 5y agoI suspect GCC thinks of its options as mainly single-option short options and double-hyphen long options. It's reasonable to interpret things like `-funsafe-math-optimizations` to mean option `-f` with argument `unsafe-math-optimizations`, just like how `-Dfoo` means option `-D` with argument `foo`. Unless you were thinking about something else.
- kevin_thibedeau 5y agoJust go through the docs. They have a ton of single hyphen long opts that aren't a letter with argument.
- mort96 5y agoHuh, you're right. I had never noticed options like `-gen-decls` or `-nostdinc` before. I also should've thought of `-static`. Yeah, that's weird. Also, I just noticed: they have `-nostdinc` for C, but the C++ equivalent is `-nostdinc++`, which looks like "no stdin C++".
- tambourine_man 5y agoIf Apple made the transition to OS X in a position of strength, like the one it enjoys today, I think it may had imposed a pattern and rewritten tar, ps, dd, etc. However, the way history has unfolded, I think we’re stuck with this mess for good.
- pjmlp 5y agoIn that case, there wouldn't be any desktop UNIX from Apple, and Copland would have managed to eventually make it.
- tambourine_man 5y agoI don't know about that. I mean, look at Longhorn. And Microsoft was unbeatable back then. Being huge and powerful is no guarantee of success when it comes to shipping software. Size can often be a hinderance.
- pjmlp 5y agoExactly because Microsoft was unbeatable, Longhorn UI ideas survived as WPF, while the OS components were rescued into C++ and COM, clunky as Windows Vista, and refined into Windows 7, including a kernel rewrite via the MinWin project. They are on a similar position nowadays, trying to fix the UWP disaster, maybe by a future Windows 12 we get what Windows 8 should have been all along. Likewise, starting from the same premise that Apple wouldn't be bleeding money, they would been able to keep up with their roadmap with System 8 and integration of Copland technologies.
- tambourine_man 5y agoCopland UI ideas and code survived and shipped in Mac OS 8. Multithreaded Finder, Platinum Theme (multiple themes in fact, though killed at the last moment), windows as tabs at the bottom of the screen. However the main challenge, memory protection, didn't. Much like Longhorn's file system.
- blacklion 5y agoExample in "Early 1970s" is notoriously bad. Text says: "it would be given some number of filenames as command line arguments, and it would read those ... Options didn’t exist". Example shows: unneeded usage of `cat` as if `wc` is non-standard utility and cannot process file names by itself, option for `wc` is used. It contradicts text in both ways!
- archduck 5y agoIs there any actual, useful, worthwhile reason for avoiding useless `cat` though?
- blacklion 5y agoAre several memory copies and context switches free for you? They are most expensive operations on modern hardware (yes, I know about splice syscall in Linux, but it is Linux-specific and don't avoid context switches). I think, on very high-end modern storage subsystem (like, stripe built out of several enterprise-grade NMVe SSDs) impact will be well-measurable in case of simple "wc".
- ElevenLathe 5y agoI can imagine if you are running 70s vintage DEC hardware, there might be appreciable performance benefits to not spawning that extra process.
- sudhirkhanger 5y agoI wish everybody would follow single and double dash convention. It keeps things simple but unfortunately not everybody does.
- thecosmicfrog 5y agoSee: Go.
- onetom 5y agoIt's interesting, that no one questioned the use of double dash itself. It looks especially silly, when long options are used to encode some mini programming language (DSL), like in imagemagick and ffmpeg, or when they are used to represent some associative data, like in case of the AWS CLI. If -- would be a : AFTER the option name, it would look like Objective C named arguments or set-words in REBOL and Red. If -- would be a : BEFORE the option name, it would look like keywords in Lisps. As a side-note, shells got quite evolved, actually, but the momentum of the mediocre bash-line prevailed, sadly. I urge people to learn about es, the Extensible Shell: https://wryun.github.io/es-shell/ https://wryun.github.io/es-shell/ Its ancestor, the Plan 9 rc (which I think stands for Run Command) and it used "; " as a prompt, so u could combine multiple commands easier, by copy-pasting whole lines, instead of fiddling with the exclusion of the varying length prompt. Both of these shells have a lot better string quoting rules than bash, so they play nicer with filenames containing special characters. They also follow the unix philosophy closer, by not necessarily providing line editing capabilities, which can be added by running them thru eg. rlwrap or not really needed, when running them from Emacs or Plan 9's acme environment. I would also highlight, that es is just 163KB, while bash is 1.3MB, yet it provides a magnitudes more powerful, dynamic, garbage collected, functional programming language!
- theamk 5y agoThe double-dash is selected for pure practicality. Any option character excludes a set of inputs, and we want this set to be as small as possible. It is already hard to look at file named "-f" -- do you want to also make accessing files named ":f" (or even worse, "f:") harder? Thus the desire to keep the first "-". Now, they could have used "-:" or "-=" for long options.. but I think "--" won because it is so easy to type -- no need to move your fingers. Using long options to encode DSL, like imagemagick and ffmpeg, can be pretty silly.. But those programs are exceptions, and most of the option usage is of much simpler variety. Like "grep --label=input --color=always". The comments about es sound weird... You can set ";" as prompt in sh/bash too. I would not call its quoting "nicer" -- yes, using '' for a single quote is nice, but lack of " support sounds like a bad omission. Yes, bash is pretty fat by 1990's standards.. but if you want a real programming language with no line editing capabilities, no need to reach for obscure shells -- grab perl, python, tcl, lua or any of the other scripting languages.
- jdnordy 5y agoI thoroughly enjoyed this post. The history of software is interesting... the process is so iterative. Often, I take for granted the current state of software I use. The refinements came through many years, many engineers, and many decisions. I wonder where I can find more posts / articles like this. short, punchy, well written histories of software I use.
- cb321 5y agoSince `ps` is featuring prominently here, folks might be interested in https://github.com/c-blake/procs https://github.com/c-blake/procs which is a color ps (Linux-only right now). It has a more canonical CLI since it is based upon the Nim CLI generator https://github.com/c-blake/cligen https://github.com/c-blake/cligen. It also uses cligen's subcommand feature (display, find, scrollsys) and so it can replace pgrep, pkill, ps, top, vmstat, etc., etc. Uses the same color scheme as https://github.com/c-blake/lc https://github.com/c-blake/lc which re-organizes the mismash ls CLI quite a bit.
- gumby 5y agoThe double dash was indeed from the GNU project and specifically RMS (though I think it was at the recommendation of someone else whose name I am blanking on). This followed an earlier GNU approach, also from RMS, of using + to signal long options. The idea, though not the syntax, came from the installation of a TOPS-20 machine and some VMS machines on a lower floor. Our own homegrown OS (ITS) used control characters as commands and had DDT as a shell. > In the beginning, in the first year or so of Unix, an ideal was formed for what a Unix program would be like… Note that the approach you’re talking about came straight from the Multics of that era, though Multics already supported some short options at that time. > None of this explains dd. Because just as Unix in many ways copied Multics, the dd command copied IBM.
- ofrzeta 5y agoIt's super annoying to have a command that was called with "-h" output "please type --help for help". And there are lots of it.
- xphos 5y agoNot sure if anyone has brought this up but I think command process in some sort flow chart similar to GNUradio but for command line would be really cool. There is this problem I face really often with that I semantically know all the small operation I want to run on command line but some of them have branching element in them. Often I just want to reconverge my data and run more commands. As one can imagine your writing in a functional way acting on raw data always but it's hard for other people to see a shell command or a bash script and really internalize the underlying operation. It would be really fancy if you could take in a command line opt and generate a corresponding flow diagram too.
- kickingvegas 5y agoWith this thread, wondering what specs/guidelines (if any) are there for common option behavior? For example, -v, —-version -o <file>, —-output=<file> if <file> is - then use stdout -i <file>, —-input=<file>. if <file> is - then use stdin -h, —-help Or is it just anarchy out here?
- conaclos 5y ago-v is also used for --verbose. In this case -V is often used for --version. Another common option I am thinking about is -r for --recursive. I could advocate to use only commonly accepted short options.
- conaclos 5y agoI found guidelines [1] that list several common short options: -a, --all -d, --debug -f, --force -h, --help -o, --output -p, --port -q, --quiet -u, --user [1] https://clig.dev/#arguments-and-flags https://clig.dev/#arguments-and-flags
- somat 5y agoI have an opinion on this, it is stupid but the more I think about it the more I am convinced I am right. getopt is lipstick on a pig. dashed argument are ugly and hard to read. The worst offenders, programs that implement a language in the args. if you do this just build a proper parser and leave off the dashes. the worst offenders. iptables find megacli megacli, remember that? it was the control application for lsi megaraid cards, it was the program that turned me off getopt style args. when I figured out that the megacli parse let you drop the dashes(and the obnoxious capitalization) it was like a breath of fresh air in a fart filled room. So a better way to do args? use dd style args. Yes dd, dd had it right all this time, I find "key=value" style args to be superior to "--key value" and don't even get me started on the absurdity of "--key=value"
- liendolucas 5y agoI try to use as much as possible long options in commands where they are available. They tend to be more descriptive and sometimes avoids to consult man pages unnecessarily.
- shcheklein 5y ago`None of this explains dd.` :) (it's at the very end of the post)