This is the mail archive of the
mailing list for the Cygwin project.
Re: Problems with 'dircolors'
-----BEGIN PGP SIGNED MESSAGE-----
> -----Original Message-----
> From: cygwin-owner AT cygwin DOT com
Phil, please avoid http://cygwin.com/acronyms/#TOFU (reformatted
accordingly) and please http://cygwin.com/acronyms/#PCYMTNQREAIYR (munged
raw address accordingly)
> Can someone explain me how dircolors work?
> I don't understand the concept of the environment variable (in this case
> - i think - LS_COLORS) and when i try 'set LS_COLORS --COLOR' it does
> nothing at all.
Are you using bash or tcsh? If you are using bash, then set is not the
right way to do things.
The short answer is you use dircolors to output raw shell script, eval
that shell snippet to set the LS_COLORS environment variable, set up an
alias so that ls is invoked with the --color option, then ls will read the
contents of the LS_COLORS environment variable.
This is done for you by default if you have not edited any files from the
According to Long, Phillip GOSS on 10/11/2006 11:41 AM:
> Hi, Ricardo!
> `dircolors' comes with its own built-in colorization scheme; that's what
> U get when U type `dircolors --print-database.' If U want to
> _customize_ your colorization scheme, dump the database to a file, like
> dircolors --print-database > dircolors.db
> make whatever changes U want, and in your `.bash_profile' file (if U're
> using `bash' as your shell), enter this line:
> eval $(dircolors -b /path/to/your/file/dircolors.db)
Actually, for bash, that should be:
eval "$(dircolors -b /path/to/dircolors.db)"
Otherwise, the output of dircolors, which contains shell metacharacters,
is subject to file globbing, and some well-named files can make this
execute arbitrary shell code (well, it's true that on cygwin, it's much
harder to make these well-named files, since Windows doesn't allow them by
default, but this is for portability to other platforms with more
tcsh has a similar requirement for properly quoting, but I don't use tcsh
to tell you what it should look like.
> Now when U open a window, `dircolors' generates a command to set the
> environment variable LS_COLORS. This is executed in a subprocess (it's
> inside a `$(...)' construct), and its output is returned as a string
> passed to `eval,' which _runs_ that command (which sets the LS_COLORS
> environment variable) in the context of the current process (sort of
> like using `source' or `.').
You forgot to mention that you must set up an alias or shell function for
ls so that it is always invoked with the --color option. Here, if you are
a bash user, the directions in /etc/DIR_COLORS are useful - edit
~/.bashrc, and add the line:
alias ls='ls -color=auto'
Life is short - so eat dessert first!
Eric Blake firstname.lastname@example.org
volunteer cygwin coreutils maintainer
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v126.96.36.199 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
-----END PGP SIGNATURE-----
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html