5 ms·
Please be careful with this. From the GNU Coding Standards: "...please don’t make the behavior of a command-line program depend on the type of output device it
by rlpb 7y ago
Please be careful with this. From the GNU Coding Standards:
"...please don’t make the behavior of a command-line program depend on the type of output device it gets as standard output or standard input."
https://www.gnu.org/prep/standards/standards.html#User-Interfaces https://www.gnu.org/prep/standards/standards.html#User-Inter...
Of course you don't have to follow their standards, but their rationale for this particular item is reasonable.
I think a warning as described in the article is perhaps just about OK though.
- jankotek 7y agoExactly, this is not an improvement, but makes it worse.
- Normal_gaussian 7y agoOK until, of course, you meet me. And I go around piping things into 'less -RS' I wouldn't get the warning. Though of course getting it to some is probably better than none so I'm more than likely with you. -- Unfortunately many apps do behave differently towards ttys in one key way - colour. It is somewhat frustrating to be piping into less something like 'apt list --upgradable' and being unable go essuly scan because its a mess without colour.
- jancsika 7y agoInstead of a warning it could grep the contents of the current directory. I bet that would work if you were imagining a use case of typing your pipeline on the command line.
- vinc 7y agoDoesn't `ls` behaves like this, printing in multiple columns when the output is a tty?
- majewsky 7y agoIt does, but it can be argued that this is not in response to a certain type of output file. ls(1) formats filename lists into columns depending on the width of the output viewport. It just so happens that it's not able to determine that width for anything but tty devices, so it falls back to the safe default "single column". To use an analogy from web browsers, the equivaleny guideline would be asking websites not to detect features by reading the User-Agent, and using feature detection instead.
- duckerude 7y agoNowadays it also adds quotes to filenames with spaces or special characters if the output is a terminal, to make copying and pasting easier.
- smorrow 7y agoWhen I first started using Plan 9 I thought it was great how it (ls)'d give results the same way you asked for them, i.e. if (cd a; ls) would print 'f' then (ls a) would print 'a/f'.
- blux 7y agoWhat exactly is the rationale though? I could not find a reason in the text for doing so, it only states, "...don't make the behavior of a command-line program depend on the type of output device...". Ok, but why?
- noisem4ker 7y agoBecause not breaking a standard abstraction is a logically sound thing to do, even if such abstraction isn't perfect for your use case. The big picture takes into account interoperability and predictability of the behavior of tools when put to work together in unforeseen ways.