2

I recently thought about a devious trick that involves setting the PAGER envionment variable to rev as a joke. When I tried reading the man page for rev with man rev I then saw the man page in reverse as expected.

If you want to try this without setting your pager you can use the -P option in man like so: man -P rev rev and you will see the man page for rev in reverse.

The thing that confuses me is that you cannot simply pipe the output through rev to get it the right way around again. I tried running man -P rev rev | rev and instead of getting the output the right way around, it is still reversed.

There is an error message displayed the correct way around, it looks like this:

mdoc warning: A .Bl directive has no matching .El (#58)

I presume this is in the correct direction because it came through stderr and not stdout

If you simply pipe it through rev again, all of the text is in the correct direction, error message and all.

man -P rev rev | rev | rev

What is the reason for this odd behaviour?

I am using bash in gnome terminal on Ubuntu.

3

This is because man does not use the pager unless output is sent to a terminal. If output is sent to a pipe instead, it will merely cat the output there. And so...

man rev | rev | rev

...and...

man -Prev rev | rev | rev

...are equivalent.

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.