Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: outputs of _users and _hosts to arrays
- X-seq: zsh-users 9157
- From: Motoi Washida <a66@xxxxxxxxxxxxx>
- To: Wataru Kagawa <wkagawa@xxxxxxxxxxxxxxxxxxxx>
- Subject: Re: outputs of _users and _hosts to arrays
- Date: Mon, 25 Jul 2005 18:15:32 +0900
- Cc: zsh-users@xxxxxxxxxx
- In-reply-to: <3BF4526D-BFA6-46C7-A977-BD43DFAD4C07@xxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <DC95ADD4-4F3C-4024-A9BE-242EC503D12C@xxxxxxxxxxxxxxxxxxxx> <1050724093315.ZM20733@xxxxxxxxxxxxxxxxxxxxxxx> <3BF4526D-BFA6-46C7-A977-BD43DFAD4C07@xxxxxxxxxxxxxxxxxxxx>
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
and,
% 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