2

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?

2 Answers 2

4

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.

1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .