有没有人在 mac 下遇到过执行 `man` 命令出问题的情况?

2019-05-07 18:10:11 +08:00
 siteshen

系统版本:10.14.4

本人未执行过任何激进升级(如预览版、测试版什么的)的行为。

为了排除特定 shell 的问题,特地用了自带的 bash 复现问题。

bash-3.2$ man man
sh: -c: line 0: syntax error near unexpected token `||'
sh: -c: line 0: `(cd '/usr/share/man' && (echo ".ll 8.3i"; echo ".nr LL 8.3i"; /bin/cat '/usr/share/man/man1/man.1') | /usr/bin/tbl | /usr/bin/groff -Wall -mtty-char -Tascii -mandoc -c | ( || true))'
Error executing formatting or display command.
System command (cd '/usr/share/man' && (echo ".ll 8.3i"; echo ".nr LL 8.3i"; /bin/cat '/usr/share/man/man1/man.1') | /usr/bin/tbl | /usr/bin/groff -Wall -mtty-char -Tascii -mandoc -c | ( || true)) exited with status 512.
Man page /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/share/man/man1/man.1 is identical to /usr/share/man/man1/man.1
No manual entry for man

升级系统安装后 man 和该目录下其他文件的创建时间接近,程序应该没被替换过。

bash-3.2$ ls -l /usr/bin/man /usr/bin/readlink
-r-xr-xr-x  1 root  wheel  70192 Mar 21 14:10 /usr/bin/man
-rwxr-xr-x  1 root  wheel  27520 Mar 21 14:09 /usr/bin/readlink

使用 strings 看了下,疑似某必须的字符串为空引起的,不过不知道怎么解决。

bash-3.2$ strings /usr/bin/man | grep true
(cd '%Q' && %s | (%s || true))
1549 次点击
所在节点    macOS
3 条回复
ptyfork
2019-05-07 20:01:24 +08:00
从报错信息看( || true) 是|| 前面缺了东西了,google 一下就知道这个是 PAGER 变量定义的,所以问题原因就是环境变量中的 PAGER 被设置为了空值

查看变量定义
```
env |grep PAGER
```

带变量执行:

```
PAGER=/usr/bin/lesss man man
```
ptyfork
2019-05-07 20:02:46 +08:00
上面写错了, 正确的应该为 PAGER=/usr/bin/less man man


用 PAGER="" man man 就能复现错误。
siteshen
2019-05-07 21:11:45 +08:00
@ptyfork 非常感谢!我确实设置了 `PAGER=`。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/561915

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX