When I try to use those environment variables, I get an empty string:

$ $PAGER some_file;
bash: some_file: command not found

I tested a few things:

$ echo $PAGER;

$ man man;     ## Here it's using less(1)
$ export PAGER;
$ man man;     ## Still using less(1)
$ PAGER='';
$ echo $PAGER;

$ man man;     ## Here it uses cat(1)
$ export PAGER;
$ man man;     ## Here it uses cat(1), too
$ unset PAGER;
$ man man;     ## Here it uses less(1) again

Why? And how can I use those variables?

env |grep PAGER shows nothing.

My system is Debian 11 (testing)


My intention is to write a script that relies on a pager.

I'd use less, but I can't guarantee it'll be present, so I'd like to use $PAGER.

Aren't those variables supposed to be always present so that I can rely on them?


man doesn’t rely on PAGER. On Debian, the tool used to view the output is determined as follows:

  • if the -P (or --pager) option is set, use that;
  • if the MANPAGER environment variable is set, use that;
  • if the PAGER environment variable is set, use that;
  • if pager exists in the path and is executable, use that;
  • otherwise (or if the pager was overridden with an empty value), use cat.

pager is less by default on Debian (see readlink -f /usr/bin/pager). The cat override won’t apply if the pager is overridden with a non-empty, but non-executable value: man -P non-existent will fail with an error.

If you want to set your own value for PAGER etc., you can add them to your shell’s startup files; for Bash (the default user shell in Debian), add them to ~/.bashrc.

The environment variables you mention (PAGER, EDITOR, VISUAL) don’t have to be present in a process’ environment, and you can’t expect them to be. They are useful to allow users to specify their preferences, but you always need a default. Some distributions try to help by providing their own generic commands, for example sensible-editor and sensible-pager in Debian. See Are the environment variables defined by POSIX for a shell, or for any process which doesn't necessarily run shell? for more discussion of this in general.

  • Oh well, I thought there was going to be something like Debian's pager that I could use everywhere. I'll use pager since I'm using Debian. I'll leave the generalization to my future me :p ...or maybe the future other distros provide pager too :-) – alx Jan 5 at 16:11
  • The man command neither has a -P option nor a --pager option. Please be careful when talking about vendor specific extensions on a UNIX platform. – schily Jan 12 at 18:59
  • 1
    @schily come on, I wrote “on Debian”. Surely it’s clear enough that I’m not talking about all Unix-style platforms. – Stephen Kitt Jan 12 at 20:12
  • If you did mention that Debian is using a clone instead of the original man implementation, this would be another way to document the difference. The problem is that most people do not know about this kind off incompatiblitiles. PAGER is known by all implementations... – schily Jan 12 at 21:43
  • 1
    @schily the phrase is in the introduction. That’s why I used quotes in my comment: I’m quoting my own answer. – Stephen Kitt Jan 12 at 22:31

There are many man implementations out there but man man from the common man-db project which is also used on Debian says:

   -P pager, --pager=pager
          Specify  which  output pager to use.  By default, man uses less,
          falling back to cat if less is not found or is  not  executable.
          This  option overrides the $MANPAGER environment variable, which
          in turn overrides the $PAGER environment variable.   It  is  not
          used in conjunction with -f or -k.


              If $MANPAGER or $PAGER is set ($MANPAGER is used in preference),
              its value is used as the name of the program used to display the
              manual page.  By default, less is used, falling back to  cat  if
              less is not found or is not executable.

So, as you observe man uses less and cat by default if neither MANPAGER nor PAGER are set.

Also, notice that in shell you don't need ; at the end of each line as in C and that exporting a variable can be done in a single line:

export PAGER=''

or just set temporarily for a single command:

PAGER='' man man
  • Re ';': I know; I just like them :) – alx Jan 5 at 15:31

To use a variable but fall back to a default, use the ${var:-default} parameter expansion:

"${PAGER:-less}" "$some_file"

To have a cascading list of defaults like man has:

for p in "$MANPAGER" "$PAGER" less cat; do
    myPager=$(type -p "$p") && break
if [[ -z $myPager ]]; then
    echo "Panic! not even cat can be found!" >&2
    exit 255

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.