0

This might be a really stupid question but I really haven't found an answer or even information that would help me with what I am trying to do. I just wanted to know if it is somehow possible to iterate over a man page's content with a python/shell etc. script (I want to have all possible parameters)? I saw that man pages are always gz-files. Is there a way to do this?

3
  • 1
    Most commands take a --help parameter that prints out all the possible parameters so you don't have to go wading through a man page. Would that do?
    – B.Tanner
    Feb 1, 2021 at 22:49
  • Unfortunately not. :) I need the parameters for a program that I am writing and it takes too long to copy/paste all of them for several commands by hand.
    – NewOasis
    Feb 1, 2021 at 23:17
  • So what part of the man page would you want exactly? Iterating is trivial (man command | script.py), the question is what you want to do while iterating. Do you want to print some lines and skip others? Print only portions of lines? Which lines? Are you trying to extract only those lines that explain command line switches? Please edit your question and clarify. Ideally, add an example man page and the output you would want to see from it.
    – terdon
    Feb 2, 2021 at 10:05

1 Answer 1

1
$man -P cat the-command-you-want | your-program

Or inside of your-program, call MYVAR=$(man -P cat the-command-you-want) and operate on MYVAR.

The man pages more often than not contain MUCH more than just the parameter and options lists (likely more than you need or want). In that case, use B.Tanner's suggestion. Inside of your script: MYVAR=$(the-command-you-want --help).

From the man manpage:

Controlling formatted output

   -P pager, --pager=pager
          Specify which output pager to use.  By default, man uses less -s...

You are in this case using cat instead of less as the 'pager', so that you do not have to scroll through the manpage.

You must log in to answer this question.

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