Ant*_*ong 5 bash zsh mac-osx passwd
第1部分
应该getent是可执行文件吗?
在我的 zsh 设置中,我可以看到 getent 实际上被定义为一个函数
$ which getent
getent () {
if [[ $2 = <-> ]]
then
grep ":$2:[^:]*$" /etc/$1
else
grep "^$2:" /etc/$1
fi
}
Run Code Online (Sandbox Code Playgroud)
如果我想从 bash shell 执行它,
bash -c "getent passwd user"
Run Code Online (Sandbox Code Playgroud)
我收到一个getent: command not found错误。
第2部分
在 Mac OSX 中,getent无论用户 ID 是否有效,都会失败。事实证明用户 ID 没有保存在/etc/passwd文件中。为什么会这样呢?还有什么替代方案呢?
在 linux、Solaris 和(我相信)*BSD 系统上,getent 是可执行文件,并且将与普通查找功能(/etc 文件、LDAP、NIS 等)查阅同一组数据库。
Os-x 不提供 getent,但您可以使用dscacheutil或dsutil程序(与目录服务后端对话)获得类似的功能。在网络上搜索“osx getent”将为您提供更多详细信息。