Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: kinda perl split ...
- X-seq: zsh-users 10058
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: kinda perl split ...
- Date: Tue, 21 Mar 2006 09:10:07 -0800
- In-reply-to: <44201CDE.5040406@xxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <442002B4.8080501@xxxxxxxxxxxxxxxxxx> <44201CDE.5040406@xxxxxxxxxxxxxxxxxx>
On Mar 21, 4:33pm, Marc Chantreux wrote:
}
} my %user;
} @user{qw( login passwd )} = split /:/;
You can still use "read".
local -A user
while IFS=: read 'user['${^=:-login passwd uid gid gecos home shell}']'
do
if (( ${user[uid]} > 100 )) { print $user[login] }
done < /etc/passwd
} http://khatar.phear.org/shell/zshEnum.html
A better way to write "enum":
enum() {
integer i=0
eval integer -g $^@='$[++i]'
}
Then you don't need "eval $(enum ...)" because enum does the assignments
for you.
You can also do it this way:
local -a user i; i=( login passwd uid gid gecos home shell )
while IFS=: read -A user
do
if (( ${user[$i[(i)uid]]} > 100 )) { print $user[$i[(i)login]] }
done < /etc/passwd
Messages sorted by:
Reverse Date,
Date,
Thread,
Author