I wanted to change the default behavior of the less command, so I added the following to ~/.profile:

LESS="$LESS -x4"
export LESS

However, the mere presence of a set LESS environment variable seems to change the behavior of the less command, since this now causes git diff to show me raw escape sequences.

More generally, the output of

LESS='' git diff


unset LESS; git diff

differs. What is the difference between having LESS unset and LESS set to an empty value (besides the former apparently implying -R)?


This has nothing to do with less, and everything to do with git. Quoting from the git-config(1) manpage (emphasis mine):

When the LESS environment variable is unset, Git sets it to FRX (if LESS environment variable is set, Git does not change it at all).

The R option of less is that which controls whether it interprets colors escapes and such, and which is NOT on by default, but is only set by git if the LESS environment variable was unset.

  • Aha! Thanks, I suspected it was something else interpreting the environment variable, but couldn’t find the right place to look. – Socob Jul 8 at 20:08
  • Both the question and accepted answer are using less and LESS which is mildly confusing with the less command. I wonder if there is a way of making it "Less" confusing?. – WinEunuuchs2Unix Jul 9 at 1:20
  • 1
    @WinEunuuchs2Unix What do you mean? less is the less command and LESS is the LESS environment variable. I’ve added the phrase “the less command” to the question, does that help? – Socob Jul 9 at 13:38

From: Using unset vs. setting a variable to empty

Mostly you don't see a difference, unless you are using set -u:

/home/user1> var=""
/home/user1> echo $var

/home/user1> set -u
/home/user1> echo $var

/home/user1> unset var
/home/user1> echo $var
-bash: var: unbound variable

So really, it depends on how you are going to test the variable.

I will add that my preferred way of testing if it is set is:

[[ -n $var ]]  # True if the length of $var is non-zero


[[ -z $var ]]  # True if zero length

Given this I surmise that git is using set -u somewhere. Although an accepted answer has already been posted, I thought people would find this information interesting.


$LESS is an environment variable used by less. From man less:

Options are also taken from the environment variable "LESS".  For example, to avoid typing
   "less -options ..." each time less is invoked, you might tell csh:

   setenv LESS "-options"

   or if you use sh:

   LESS="-options"; export LESS

You should use some other environment variable name.

  • 2
    Yes, the OP seems to know this. The weird thing is that empty $LESS and unset $LESS don't behave the same way. The question isn't asking what $LESS is but why less seems to display different behavior when the variable is set to empty vs when it is unset. – terdon Jul 8 at 17:13
  • apt-get source less and start reading. – waltinator Jul 10 at 1:53

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.