Use Man's Exit Status from a Function
The man(1) manual page defines the following exit status codes:
EXIT STATUS
0 Successful program execution.
1 Usage, syntax or configuration file error.
2 Operational error.
3 A child process returned a non-zero exit status.
16 At least one of the pages/files/keywords didn't exist or wasn't
matched.
That means you can use the exit status of man itself to determine if a page is available via manpath. For example:
check_for_man_page () {
man "$1" > /dev/null 2>&1
}
With this function, you can use test conditionals on the exit status like so:
$ check_for_man_page "cat" && echo 'Found it!'
Found it!
$ check_for_man_page "quux" || echo 'Not found!'
Not found!
Using an If/Else Statement
Here's another way to do this, using an if/else statement to determine whether to run your original code:
if man "$1" > /dev/null 2>&1
then
man -t ${1} | ps2pdf14 - > "${1}_man.pdf"
else
echo "Missing man page: $1" >&2
fi