Live data from Hacker News

Unix command line conventions over time

blog.liw.fi

51–60 of 222 posts

Re: Unix command line conventions over time

#51
post #21

> Initially, GNU used the plus (+) to indicate a long option Some tools still use +options, like dig(1).

Also 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).

Dash just implements the behavior specified by POSIX/SUS.

Re: Unix command line conventions over time

#52
post #29

Earlier quoted context omitted.

I 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: ch…

If all of this matters so much, don’t use an (interactive) shell.

We're not talking about the shell, we're talking about the options parser. Nothing in my examples invokes any shell.

Re: Unix command line conventions over time

#53
post #51

Earlier quoted context omitted.

Also 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).

Dash just implements the behavior specified by POSIX/SUS.

In hindsight, indeed! They just go straight into `set`.

Re: Unix command line conventions over time

#54
post #40

The chronology is wrong. dash-options came before pipes. The first edition already has them while pipes came in the third edition.

As supporting evidence, the Unix Manual from 1971, 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

Re: Unix command line conventions over time

#55
post #18

Earlier quoted context omitted.

> that means we only can keep --long=x Just wondering: why `--long=x` over `--long x`?

`--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.

If we were starting from scratch, we could require some marker on flags which take values. Perhaps it would have to be `--long: x`. `--verbose x` would be read as a flag with no argument, followed by a positional argument.

Re: Unix command line conventions over time

#57
post #47

Earlier quoted context omitted.

> 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

> 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://en.wikipedia.org/wiki/Tar_(computing)

See also "tap" from v1, to "manipulate DECtape", described at 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.

Re: Unix command line conventions over time

#58

And then you have ImageMagick where the order of flags and options is a science by itself.

Also 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.

Re: Unix command line conventions over time

#60
post #46

And then you have ImageMagick where the order of flags and options is a science by itself.

Indeed, I passionately hate programs where the order of the options and files/arguments matter just as much as the options themselves.

Given 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.

Post reply on HN