Searching the whole DB for a whole word requires using --regex and
then using word boundaries. So to find pages that reference the TZ
environment variable, this *should* work (in principle):
$ man -aK --regex '\<TZ\>'
It appears to work because it finds many pages. But it misses the
“tree” package (/usr/share/man/man1/tree.1.gz).
$ zgrep 'TZ' /usr/share/man/man1/tree.1.gz
\fBTZ\fP Timezone for timefmt output, see \fBstrftime\fP(3).
As you can see, the nroff language intereferes with matching the
regular expression as “TZ” is surrounded by code. Users of man-db
obviously do not intend to have their regex matched against nroff
code. Thus operations are being performed in the wrong order. The
regular expression matching needs to happen on nroff-decoded text.
$ zcat /usr/share/man/man1/tree.1.gz | nroff -man | grep '\<TZ\>'
TZ Timezone for timefmt output, see strftime(3).
* Workaround *
One approach:
$ find /usr/share/man/ -iname \*gz -exec zcat {} + | nroff -man | grep '\<'"$whole_word"'\>'
In rare situations such as environment variable searches, case
sensitivity can be leveraged:
$ man -aKI --regex TZ