In my .bashrc I have the following lines to turn on colors for grep and ls

alias ls='ls --color=auto'
export GREP_OPTIONS='--color=auto'

I've tried changing the alias to export LS_OPTIONS='--color=auto' but that doesn't work. Is there anyway to use an export instead of alias. And are there actually any benefits to one way over the other?

migrated from stackoverflow.com Sep 15 '11 at 7:26

This question came from our site for professional and enthusiast programmers.


Seems like LS_OPTIONS is more a Operating System startup configuration in some Linux/UNIX systems. ls won't read that variable, so it seems that the only viable option is the alias thing.

You can combine things to do what you want, though. For instance, just define ls as an alias like this:

alias ls='ls $LS_OPTIONS'

and then changing LS_OPTIONS will actually take effect immediately.


Unlike the Gnu grep command, the Gnu version of the ls command doesn't examine the environment variable LS_OPTIONS. Setting it doesn't do you any good unless you alias the ls command itself to use it:

$ alias ls="ls \$LS_OPTIONS"
$ ls      #Doesn't display color
$ export LS_OPTIONS="--color=auto"
$ ls      #Displays directory in color
$ unset LS_OPTIONS
$ ls      #Back to old behavior

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.