3

Part 1

Is getent supposed to be an executable?

In my zsh setup, I can see getent is actually defined as a function

$ which getent   
getent () {
    if [[ $2 = <-> ]]
    then
        grep ":$2:[^:]*$" /etc/$1
    else
        grep "^$2:" /etc/$1
    fi
}

If I want to execute it from bash shell,

bash -c  "getent passwd user"  

I get a getent: command not found error.

Part 2

In Mac OSX, getent fails regardless if the user id is valid or not. It turns out the user id is not kept in the /etc/passwd file. Why it is so? And what is the alternative?

Anthony Kong
  • 2,976
  • 10
  • 53
  • 91

2 Answers2

4

On linux, Solaris and (I believe) *BSD systems getent is an executable and will consult the same set of databases as normal lookup functions (/etc files, LDAP, NIS etc).

Os-x doesn't provide getent but you can get similar functionality using the dscacheutil or dsutil programs (which talk to the directory services back end). A web search for "osx getent" will give you more details.

Paul Haldane
  • 4,457
  • 1
  • 20
  • 31
-1

getent AND dsutil fail for me as well on OSX bash.

As Paul points out above, this command dscacheutil will work. I was able to get the specific user verified with this command:

dscacheutil -q user -a name <username>. 

A list of users with this command

dscacheutil -q user | grep 'name:'
Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
  • I've removed about half this post as it had nothing to do with the question. If you have a question about using `!` in a `grep` command, you need to post it separately by clicking the [Ask Question](/questions/ask) button. (Or don't, you can find the answer [here](https://superuser.com/q/133780/144961).) – Michael Hampton Sep 06 '18 at 20:55