1

When I

man -k "^printf"

in terminal, it returns duplicated results below:

printf(1)                - formatted output
printf(1)                - formatted output
printf(3), fprintf(3), sprintf(3), snprintf(3), asprintf(3), dprintf(3), vprintf(3), vfprintf(3), vsprintf(3), vsnprintf(3), vasprintf(3), vdprintf(3) - formatted output conversion

And, When I

man -k 1

It also returns a bunch of duplicated results.

It's a new M1 MAX Mac, I didn't even do any setting changes yet, but the problem above is actually happening. What's wrong with my new Mac?

5
  • The difference between (1) and (3), at least, is that printf(1) is a command-line tool, while printf(3) is the family of library functions (which printf(1) makes use of). I'm not sure why printf(1) is listed twice, but I can reproduce it and consider it harmless. Commented Feb 21, 2022 at 14:28
  • @chepner how do you reproduce the twice-listed issue? Commented Feb 21, 2022 at 16:30
  • Not entirely sure :) I get the duplicate result on my M1 laptop (macOS 11.5.2), but not on my intel iMac (macOS 10.15.7). Commented Feb 21, 2022 at 16:39
  • @chepner The issue is really annoying. When I do “man -k 1”, it actually lists the whole output twice. Commented Feb 21, 2022 at 16:41
  • @chepner I tried the same thing on my wife’s M1 chip macbook 2020 model. It has no such issue though. Commented Feb 21, 2022 at 16:44

3 Answers 3

1

There's a bug in Apple's man(1), as recently as Ventura 13.4.1. If you have groff(1) in your path and there is no preformatted "cat" page, then the requested page will be displayed twice.

In /usr/bin/man, see function man_display_page(). If groff(1) is on $PATH, then man_display_page_groff() is called (which displays the page the first time), after which the script should return; but it erroneously falls through and displays the page a second time. The issue was flagged downstream here:

https://github.com/Homebrew/homebrew-core/issues/133561

I've also reported the issue to Apple via feedbackassistant.apple.com (these tickets cannot be publicly shared).

Sign up to request clarification or add additional context in comments.

Comments

0

You could do man -w and see where the man looks for manpages. This issue (duplication of results while using man -k printf) arises, if your system has copies of manpages in multiple path.

In my system there are multiple man paths. See below the output of my man -w.

/usr/local/opt/w3m/share/man/de:/usr/local/opt/w3m/share/man:/usr/local/opt/binutils/share/man:/Users/xx/opt/anaconda3/share/man:/usr/local/share/man/de:/usr/local/share/man:/usr/share/man:/Library/TeX/texbin/man:/opt/X11/share/man:/Library/Apple/usr/share/man:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/share/man:/Applications/Xcode.app/Contents/Developer/usr/share/man:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/share/man

Out of this, below two has some of the manpages replicated. For example printf can be found in both path.

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/share/man/

/usr/share/man/

If you do ls -l in the MANPATH, you will see that both has copies of some of the same manpages.

 > ls /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/share/man/
man1 man2 man3 man4 man5 man6 man7 man8 man9 mann


> ls /usr/share/man/
man1 man4 man5 man6 man7 man8 man9 mann

In short, when you do man -k somecommand, it displays results from all the paths contained in man -w. If you want to avoid that you need to change the $MANPATH environment variable. Set it to the path you want your man command to look.

6 Comments

I don’t get what you trying to tell, Thank you for answering my question though!
Updated answer. Could you try man -w and paste the output?
Can you do man -w printf. Then add the displayed path to $MANPATH and try to do the man -k printf again and checks whether there are any duplicates now? Let me know, if this works or not!
man -w out puts >>> /usr/share/man:/Library/Apple/usr/share/man:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/share/man:/Library/Developer/CommandLineTools/usr/share/man
I guess the solution is to run /usr/libexec/makewhatis to reset & update the man db to the newest version. The problem is that it would occur error >>> makewhatis: /usr/share/man/whatis.tmp: Read-only file system
|
0

As Kurt Starsinic pointed out, there is a bug in macOS man binary.

We could fix the problem via following steps to override system man:

brew install man-db
cd $(brew --repo)/bin
ln -s gman man

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.