Moin,
Quote:
Originally Posted by NsearchOf
How would you get the same result using an array?
|
an array makes sense for a variable list of parameters. The code below assigns the user list values to the array variable "usr_arr" using the already shown mechanism and then iterates over the array's members:
Code:
while IFS=: read group password gid user_list; do
usr_arr=(${user_list//,/ })
for ((i=0; i<${#usr_arr[*]}; i++)); do
echo group $group ${usr_arr[$i]}
done
done < /etc/group
The important part is the second line: The array is defined this way:
Code:
usr_arr=(user1 user2 user3)
because the parameter expansion within the braces
${user_list//,/ } replaces all "," by spaces - so every user name becomes a separate item of the array. If you would assign
$user_list - means "user1,user2,user3", you would get only one item.
Jan