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

Re: array as loopvariable - howto



On May 8, 11:58am, jarausch@xxxxxxxxxxxxxxxxxxx wrote:
} 
} for User in (User1,100) (User2,120); do  echo "$U[1] has UID $U[2]";
} done

I've seen responses on how to do this with the new multi-variable "for"
syntax in 4.1, but nothing about how to do it in 4.0.

I'd say the obvious solution is an associative array.

4.1 multi-variable "for":

for user uid in User1 100 User2 120 ...; do echo $user has UID $uid; done

4.0 or 4.1 associative array:

typeset -A umap; umap=( User1 100 User2 120 ... )
for user in ${(k)umap}; do echo $user has UID $umap[$user]; done



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