6 ms·
can you please explain how this works?
by aeon10 13y ago
can you please explain how this works?
- shabble 13y agoit's quite a common pattern in commandline apps to check if the stdout is a tty or not, and do things differently if so. So when you pipe it through `cat', it does the no-fancy-included output, much like the colouring that `ls' will apply interactively, but not when piped/redirected.
- ajuc 13y agoIt's important for grepping and sedding - the colors are escape codes and would mess with your regular expressions otherwise (you want to find foobar , but bar was blue so you got foo\e[1;34mbar\e[0m instead, and it doesn't match with foobar).
- jlgreco 13y agoOn the other hand, if you want colors displayed you can force grep/ack to display the color 'always' and then pipe the output into 'less -R'. The -R (or --RAW-CONTROL-CHARS) flag has less display output such that color escape sequences work as you might expect, coloring the output displayed by less.
- jasomill 13y agols | cat is also useful because it forces single-column output.
- caw 13y agoIsn't that the same as ls -1?
- gpvos 13y agoMostly, yes, except that ls -1 does not turn off colours, and maybe there are a few more differences.
- Ziomislaw 13y agoI can't imagine why anyone would want to spawn another process instead of just RTFM, if you are on linux: ls --color=never -1
- oneeyedpigeon 13y agoBecause, in many - if not most - situations, spawning another process is insanely lightweight compared to the cognitive/physical load of your alternative (which includes remembering the switch and its value ("never" is hardly intuitive), remembering whether or not you're using a system that supports it (surprise, surprise, OSX doesn't), and typing all those extra characters). Admittedly, I never actually do this because I don't ever care to not see colour (what would be the motive?), but I can understand why the OP does what they do.
- syncsynchalt 13y agoYou are Randal L. Schwartz and I claim my five pounds. [http://partmaps.org/era/unix/award.html http://partmaps.org/era/unix/award.html]
- prakashk 13y agoColor output is not on by default in 'ls'. Your 'ls' must be an alias for the real ls with some options. For example, mine is: $ type ls ls is aliased to `ls --color=auto' A quick way to run the original 'ls' (not the aliased version), just prefix it with backslash: $ \ls ... Or: $ command ls ...