Which file defines the LESSOPEN environment variable

configurationenvironment-variablesless

On my Linux machine – I do the following:

$ env | grep -i LESSOPEN
LESSOPEN=|/usr/bin/lesspipe.sh %s

So from env command I see that:

LESSOPEN=|/usr/bin/lesspipe.sh %s

I want to change the variable LESSOPEN, so I do the following search in order to find where it's located, so I can make this change.

$ grep -Ril "LESSOPEN" /

But the grep search did not find any such file with LESSOPEN.

Best Answer

On Red Hat and CentOS systems, it is defined in /etc/profile.d/less.sh. On version 5, this contains

# less initialization script (sh)
[ -x /usr/bin/lesspipe.sh ] && export LESSOPEN="${LESSOPEN-|/usr/bin/lesspipe.sh %s}"

On other systems, such as version 7, the value may be ||/usr/bin/lesspipe.sh %s; there is a slightly different interpretation between values that begin with | and ||, detailed in the man page for less.

You can either edit that file if you want all users of bash-like shells on your system to see a different value, or override it for yourself by editing ~/.bashrc or ~/.bash_profile to have an export LESSOPEN=whatever line.

On Linux systems, grep -r string / or grep -R string / may run into problems when reading certain special files. grep will hang when reading /dev/rfkill, and, due to what I believe is a buffer allocation bug, will run out of memory reading certain large files in /proc. An alternative is to exclude /dev and /proc:

find / '(' -path /proc -o -path /dev ')' -prune -o -type f -exec grep -il lessopen {} +
Related Question