Include variables from external files or shell commands in custom man page? Include variables from external files or shell commands in custom man page? shell shell

Include variables from external files or shell commands in custom man page?


I see from your example line that you're using Git - I believe you can use a 'pre-commit' git hook (basically a script that runs before your commit is processed) to update the contents of the manpage (and stage the changes) on every commit.

For example, you could put the following commands in your .git/hooks/pre-commit file to update the contents of the manpage in place whenever you commit:

sed -i "" "s/^.TH foo 1 \".*/.TH foo 1 \"$(date)\"/" path/to/manpage.roff git add path/to/manpage.roff

Note that the path is relative to the root of the git repository.


Consider composing the content of the man page using a documentation generator language like asciidoc, which has most of the desired features. The asciidoc format can include external input files, and change all sorts of things on-the-fly as needed.

To include shell script, see Substitutions inside literals in Asciidoc.

Or one could use a shell script to generate a config file, then include that file.

Apologies in advance if this answer is at present little vague, in that it's more of a software recommendation (without any actual code) than a real answer.