Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: outputs of _users and _hosts to arrays

Hi Wataru,

On 07/25/2005, at 14:18, Wataru Kagawa wrote:

Hi Bart,

Thanks for the help.
After googling, I found out that _users extract usernames from /etc/ passwd and _hosts extract hostnames from /etc/hosts.

So, I can use parameter expansions like,

users=( ${$( cat /etc/users | cut -d : -f 1,7 | grep -v "#" )//:*/} )
If you do that on Mac OS X, maybe you can't get even your name. ;-)
The more general way is using $userdirs special variable.

Load zsh/parameter module,

% zmodload -i zsh/parameter


% users=( $userdir[(I)*] )

I think you can also get user names by calling hash builtin function. But I had to rebuild named directory hash table to get expected results on some platforms.

You might need to call this,

% builtin hash -fd

and get hash table entries,

% users=( ${${(f)"$(builtin hash -d)"}%\=*} )

hosts=( ${$( cat /etc/hosts | cut -d : -f 1,7 | grep -v "#" )//:*/} )

to get what I need.
This has the same problem, but I don't know a better way well. Using some functions from Perl or some other language?

Messages sorted by: Reverse Date, Date, Thread, Author