Q:

Unexpected Bash completion of ~ on OS X

I pressed ~TabTab on the bash command prompt and got an unexpected set of completions.
First it looked like all the folks in the /Users directory, and a lot more.
Then I thought it was doing the reverse lookup of folks with "home" directories in /etc/password, or perhaps the ones that were /var/empty -- this seems about right.
What I'm curious about is what's really going on and why this works as it does.

A:

I don't have an OSX system handy to check on but on all *nixes, ~foo is a shorthand for the home directory of user foo. For example, this command will move into my user's $HOME (cd ~ alone will move into your home directory):
cd ~terdon

So, ~ and Tab will expand to all possible user names. The list should be the same as the list of users in /etc/passwd.
I can confirm that that is exactly what happens when I try this on my Debian.  

