0
man -P whoami ls

This command will output user's name, just like whoami. But when you use pipe to redirect it to a file or to your screen like man -P whoami ls | cat or man -P whoami ls > file, the contents of file will be the man page of ls.

Why are the two things different? I mean, man -P whoami ls and man -P whoami ls | cat output different.

Is there any problem?

enter image description here

2
  • Why do you want to do this?
    – muru
    Sep 19, 2015 at 1:54
  • I want to set a problem that the players can only use man command to do what he want. For example, there is a flag.txt in /tmp directory and he can use man -P 'ls /tmp' ls to get /tmp and use man -P 'cat /tmp/flag.txt' ls to capture the flag.
    – Mr.m
    Sep 19, 2015 at 4:51

1 Answer 1

2

man doesn't use a pager if the output is not a terminal but a file or a pipe. So the -P option is ignored in that case.

4
  • So, can you tell me how to make it possible? Thank you very much!
    – Mr.m
    Sep 19, 2015 at 1:53
  • 1
    What do you actually want to to? Sep 19, 2015 at 1:54
  • I want to set a problem that the players can only use man command to do what he want. For example, there is a flag.txt in /tmp directory and he can use man -P 'ls /tmp' ls to get /tmp and use man -P 'cat /tmp/flag.txt' ls to capture the flag. Thanks a lot!
    – Mr.m
    Sep 19, 2015 at 4:48
  • The player could do something like man -P 'sh -c "ls /tmp/ > ls.txt"' ls Sep 19, 2015 at 14:13

You must log in to answer this question.

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