The LESS environment variable to man and how is it set up

environment-variableslessman

What is the LESS environment variable used for in man? I found that it could make the output of man jump to a match to the pattern stored in LESS. What about when there are several matches?

How is the pattern set up in LESS? What kind of regex is used?
For example,in LESS=+/'^ *shopt \[' man bash, what does +/ mean?

Does LESS affect other commands than man?
Is it possible to achieve the same in the std output of another command?

Best Answer

LESS has no special meaning to man, but less pager, which man uses by default on most systems.

On my Debian, if no pager was specified, man will use pager -s by default.

$ readlink -f "$(command -v pager)"
/bin/less

LESS specifies which options will be passed to less. The +cmd tell less to execute cmd upon open. Here +/'^ *shopt \[' tells less to search for line match regex ^ *shopt \[, which you can do manually by running man bash, then pressing / and typing the regex.

If you change the pager, LESS has no effect:

LESS=+/'^ *shopt \[' man -P more bash