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

Re: kinda perl split ...



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