4

I wanted to redirect mc's man page to a text file using man mc > mc, but I accidentally executed man mc > mc grep. What resulted was a text file named mc containing two concatenated mc man pages.

I then tried man ls > 1 abc, which resulted in text file named 1 containing the ls man page and an error message in the terminal: No manual entry for abc.

Next I tried man du > du ls tac. I expected three concatenated du man pages, but what actually resulted was a text file named du containing the man pages of du, ls and tac concatenated.

Why did each command produced the results it did?

5
  • In the first case, what was the resulting text file’s name? (Presumably mc...) Commented Dec 23, 2018 at 16:07
  • @Stephen Kitt: Yes, mc.
    – EmmaV
    Commented Dec 23, 2018 at 16:11
  • I can't reproduce the first finding - I get mc and grep in mc, which is to be expected.
    – tink
    Commented Dec 23, 2018 at 16:41
  • I would expect mc and grep man pages in a file called mc for first example. Commented Dec 23, 2018 at 16:45
  • Hi EmmaV, I wondered if you would consider accepting my Answer? If you think it could use improvement in some way, please let me know how.
    – cryptarch
    Commented Jan 3, 2019 at 20:57

2 Answers 2

4

This is consistent with a relatively obscure part of the Bash manual, which states under the section Shell Grammar:

A simple command is a sequence of optional variable assignments followed by blank-separated words and redirections, and terminated by a control operator. The first word specifies the command to be executed, and is passed as argument zero. The remaining words are passed as arguments to the invoked command.

(Emphasis mine.)

What that means is that you can "mix" any redirections in with the command and its arguments.

For example, echo > world hello is equivalent to echo hello > world.

In other words, when you run a command like man du > du ls tac, it is equivalent to running:

man du ls tac > du

That these three manpages all end up concatenated into a file named du is then the result of how man behaves when its output is being redirected or piped: it will no longer try to use a pager and will essentially act like cat.

0

Only for reference/curiosity:

I know I'm not answering your question but in case you need to redirect the content of a man page you can do it with col(1)

man 1 col | col -b -x > manfile.foo

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .