Gentoo Archives: gentoo-dev

From: Ulrich Mueller <ulm@g.o>
To: "Michał Górny" <mgorny@g.o>
Cc: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] [PATCH] user.eclass: Fix egetgroups bash compliance, and make it simpler
Date: Thu, 25 Jul 2019 08:14:27
Message-Id: w6gef2ezg30.fsf@kph.uni-mainz.de
In Reply to: [gentoo-dev] [PATCH] user.eclass: Fix egetgroups bash compliance, and make it simpler by "Michał Górny"
1 >>>>> On Thu, 25 Jul 2019, Michał Górny wrote:
2
3 > - local defgroup=${egroups_arr[0]}
4 > + local g groups=( "${egroups_arr[0]}" )
5 > # sort supplementary groups to make comparison possible
6 > - readarray -t exgroups_arr < <(printf '%s\n' "${egroups_arr[@]:1}" | sort)
7 > - local exgroups=${exgroups_arr[*]}
8 > - echo "${defgroup}${exgroups:+,${exgroups// /,}}"
9 > + while read -r g; do
10 > + [[ -n ${g} ]] && groups+=( "${g}" )
11 > + done < <(printf '%s\n' "${egroups_arr[@]:1}" | sort)
12 > + groups=${groups[*]}
13 > + echo "${groups// /,}"
14 > }
15
16 Why don't you make groups a scalar variable (i.e., a comma separated
17 list) from the very beginning, if you're converting to it later anyway?
18
19 local g groups=${egroups_arr[0]}
20 # sort supplementary groups to make comparison possible
21 while read -r g; do
22 [[ -n ${g} ]] && groups+=",${g}"
23 done < <(printf '%s\n' "${egroups_arr[@]:1}" | sort)
24 echo "${groups}"

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies