4 ms·
I saw the majority of his complaints as basically "it's too hard/unfamiliar", a sentiment which I don't really agree with as I've noticed the steepness of learn
by userbinator 12y ago
I saw the majority of his complaints as basically "it's too hard/unfamiliar", a sentiment which I don't really agree with as I've noticed the steepness of learning curve of various software tends to be correlated with how powerful it is - those who give up early might not see that.
Inconsistent command names shouldn't be a difficulty - shell commands are like any other language, whose vocabulary is quickly learned with repeated use.
The manual doesn't bother warning against this either, although it does warn of another, related infelicity: "Beware of 'cat a b > a' and 'cat b a > a', which destroy the input files before reading them."
I'd consider it generous to see a mention of shell redirection in cat's manual, since that's done before it ever gets executed; in general, interactions between commands can't be exhaustively documented because they are numerous, and Unix assumes you can put two and two together.
..or maybe I'm just old and accustomed to it, after having used various OSs over the years, but that's sort of the point: Thanks to this "lowest-common-denominator" type of interface design, ease-of-use seems to have massively replaced learning, dissuading and distancing users from having control of their machines at a time when such control is becoming increasingly important.
- lukeschlather 12y agoThe result of `cat a b > a` couldn't possibly be the result that the user intends, so it seems like poor design by definition. I can see how it would be tricky to handle it properly, but I do think it's possible to handle it properly without compromising the expressiveness of the shell.
- marvy 12y agoAt first I was going to say that handling this properly would require shell to have magic powers. After trying to come up with a proof of why it's impossible, I think I found a simple solution. There are two problems the author was complaining about. The first one is: cat paper.* > paper.all This has the potential to use up the whole disk. The fix here is easy: do globbing before redirection. But this does not solve the other problem: cat a b > a This has a simple workaround which is even easier to type: cat a >> b. But the trap remains. How could the shell fix it? By pretending the user wrote this instead: cat a b > temp; mv temp a Let's look at the trade offs. We do a bit of extra work: one rename operation. This should be pretty cheap, and solves this problem as well as paper.all. The real trouble I think is coming up with a good name and location for tmpfile that is guaranteed not to mess up the operation of the command we're running. If we put it in the current directory, we get the wrong answer from ls. If we put it in /tmp, it will mess things up when we're working in /tmp. However, after doing a few minutes of research, it appears that this problem is already solvable on Linux: by using the O_TMPFILE flag, there is no need to give the file a name at all, until after the command finishes running.
- voyou 12y agoSometimes I start a long-running process, redirecting it's output, and periodically look at the output file while this process is running. Your proposed solution wouldn't allow for that.
- marvy 12y agoIt would be possible, but not convenient: /proc/pid/fd/1. Ick. Ok, maybe the cure is worse than the disease. I'm out of clever ideas for now.
- hackmiester 12y agoWhat if 'a' is a device?
- marvy 12y agoOuch. Don't do that for devices. Or named pipes I guess. This idea has more problems than I thought at first.
- pdkl95 12y agoIn modern bash, this case is already protected with the "noclobber" option (enabled with "set -C" or "set -o noclobber"). It is described in the "REDIRECTION" section of bash(1), subsection "Redirecting Output". It fails ">" redirections with an error message when it would clobber an existing file (you probably wanted to append to the file wiht ">>"). If you really intended this behavior, the new redirection operator '>|' has the old behavior. $ set -o noclobber $ echo foo > bar $ cat bar foo $ cat bar > bar bash: bar: cannot overwrite existing file $ echo baz > bar bash: bar: cannot overwrite existing file $ echo baz >| bar $ cat bar baz edit: fixed typo
- girvo 12y agoThat's a nice feature, but it should definitely be turned on as a default rather than hidden behind an option.
- pdkl95 12y agoThat would break a very large number of existing scripts that depend on being able to replace a file with a traditional ">" redirection. You can set it as the default for your own interactive shell if you want by adding set -o noclobber to your ~/.bashrc file. It is probably a good idea to add it after the line that check if it is being used non-interactively, which probably looks something like this if [[ $- != *i* ]] ; then # Shell is non-interactive return fi # add interactive-shell-only settings here While you're editing .bashrc, you may want to also add these options that are available in modern bash that I find make the experience a lot nicer. # support new glob patterns like !(foo|bar|...) # for example, this move everything EXCPET the .h files # mv !(*.h) /some/dir/ shopt -s extglob # support ** in globs to match zero-or-more-recursive-directories shopt -s globstar # if you're annoyed at having to type "nohup" to prevent # programs from closing when you close the shell window shopt -u huponexit
- girvo 12y agoRight, it definitely would break a lot of existing scripts, so I understand why its not a default. The thing is though, that really proves the argument that some parts of Unix have a bad out of the box user experience! I personally love Unix and find it amazingly powerful, but I've made the same mistakes as everyone and killed entire boxes, and really with some simple UX changes that could be fixed in the bulk of cases. Edit: I forgot to add, thanks for the detailed answer!
- weland 12y ago> The result of `cat a b > a` couldn't possibly be the result that the user intends The result of cat a b > a is precisely the result that the user intends, provided that the user has actually read the documentation.
- sjolsen 12y ago>I saw the majority of his complaints as basically "it's too hard/unfamiliar", a sentiment which I don't really agree with as I've noticed the steepness of learning curve of various software tends to be correlated with how powerful it is - those who give up early might not see that Many powerful systems are unfamiliar and difficult to use— but a system that is unfamiliar and difficult to use is by no means necessarily powerful. At any rate, the issue isn't that Unix is difficult to use, because it isn't. What's difficult is using it well. What's difficult is learning all the idiosyncrasies, all the details you have to get right to write good software in the Unix ecosystem. What's difficult is learning when and why rm * does not do what you expect, recognizing the flaw in code like mv "$PROJECT_ROOT"/* . that can nuke your entire machine because the default semantics of the Unix shell are... well, questionable. The thing is, using Unix well isn't difficult because the individual things you have to learn are difficult; the problems with the above commands are very simple and easy to address. Using Unix well is difficult because these problems arise goddamn everywhere. >Inconsistent command names shouldn't be a difficulty - shell commands are like any other language, whose vocabulary is quickly learned with repeated use. >I'd consider it generous to see a mention of shell redirection in cat's manual, since that's done before it ever gets executed; in general, interactions between commands can't be exhaustively documented because they are numerous, and Unix assumes you can put two and two together. Excuses. Inconsistent anything is a difficulty. The user of a system should not have to compensate in any capacity for the failure on the part of the system's designers to ensure consistency— of names of all things. That interactions between parts of the same system are so complex that it would be an act of generosity to document them is not the mark of a powerful system; it is the mark of a poorly designed one. And that's the thing: Unix is poorly designed. Maybe it was revolutionary nearly a half-century ago, but if someone unveiled an operating system, today, built on passing around and interpreting ASCII-encoded strings, with the occasional undecorated integer thrown in for kicks, they'd be laughed out of the room. >Thanks to this "lowest-common-denominator" type of interface design, ease-of-use seems to have massively replaced learning, dissuading and distancing users from having control of their machines at a time when such control is becoming increasingly important. This is happening, to a degree. However, there is a very important distinction to be made between the sort of "ease of use" that comes from reducing a system to a minimal high-level mode of interaction, and the sort of "ease of use" that comes from fixing the mistakes of previous iterations of the interaction model. Replacing the process of learning the aforementioned inconsistencies, pitfalls, and general frustrating complexities of Unix and its descendants with a system of equal or greater power that is genuinely easier to use is not a bad thing. It's just really, really freaking difficult. Or at least, no one seems to have done it yet.
- cm2187 12y agoit's not more powerful to use "cp" instead of "copy" or "usr" instead of "user".
- thrownaway122 12y ago/usr? Stands for unix system resources doesn't it? cp was named in another time when terminals were a lot slower.
- cm2187 12y agoFor usr that's not what the article suggests (p3), but I am no authority on this question.