On 2008-07-13, Niklaus Kuehnis wrote:
> Jim Cochrane wrote:
>
>> [1] I don't believe the "alias ls" options (color, etc.) should take effect
>> if the output is redirected.

>
> I believe they should:
> $ ls --color | less
> ESC[01;32mbunzip2ESC[0m*
> ESC[01;32mbzcatESC[0m*
> ESC[01;36mbzcmpESC[0m@
> ESC[01;32mbzdiffESC[0m*
> ESC[01;36mbzegrepESC[0m@
>
> $ ls | less
> bash*
> bunzip2*
> bzcat*
> bzcmp@
> bzdiff*
> bzegrep@


I see that you're correct. My ls is alised to 'ls --color=auto', which
I've just discovered is why the color option is not used for redirection
under my standard login. It fooled me into thinking that the extra
(--color, -F, etc.) output characters were not produced when the output
is redirected. This is true only for the --color=auto option:

LS(1) User Commands LS(1)

....

By default, color is not used to distinguish types of files. That is
equivalent to using --color=none. Using the --color option without the
optional WHEN argument is equivalent to using --color=always. With
--color=auto, color codes are output only if standard output is con-
nected to a terminal (tty). The environment variable LS_COLORS can
influence the colors, and can be set easily by the dircolors command.


--