Re: [gentoo-dev] [PATCH] user.eclass: Fix egetgroups bash compliance, and make it simpler
On Thu, 2019-07-25 at 10:14 +0200, Ulrich Mueller wrote: > > > > > > On Thu, 25 Jul 2019, Michał Górny wrote: > > - local defgroup=${egroups_arr[0]} > > + local g groups=( "${egroups_arr[0]}" ) > > # sort supplementary groups to make comparison possible > > - readarray -t exgroups_arr < <(printf '%s\n' "${egroups_arr[@]:1}" | > > sort) > > - local exgroups=${exgroups_arr[*]} > > - echo "${defgroup}${exgroups:+,${exgroups// /,}}" > > + while read -r g; do > > + [[ -n ${g} ]] && groups+=( "${g}" ) > > + done < <(printf '%s\n' "${egroups_arr[@]:1}" | sort) > > + groups=${groups[*]} > > + echo "${groups// /,}" > > } > > Why don't you make groups a scalar variable (i.e., a comma separated > list) from the very beginning, if you're converting to it later anyway? > > local g groups=${egroups_arr[0]} > # sort supplementary groups to make comparison possible > while read -r g; do > [[ -n ${g} ]] && groups+=",${g}" > done < <(printf '%s\n' "${egroups_arr[@]:1}" | sort) > echo "${groups}" Indeed. Will do. -- Best regards, Michał Górny signature.asc Description: This is a digitally signed message part
Re: [gentoo-dev] [PATCH] user.eclass: Fix egetgroups bash compliance, and make it simpler
> On Thu, 25 Jul 2019, Michał Górny wrote: > - local defgroup=${egroups_arr[0]} > + local g groups=( "${egroups_arr[0]}" ) > # sort supplementary groups to make comparison possible > - readarray -t exgroups_arr < <(printf '%s\n' "${egroups_arr[@]:1}" | > sort) > - local exgroups=${exgroups_arr[*]} > - echo "${defgroup}${exgroups:+,${exgroups// /,}}" > + while read -r g; do > + [[ -n ${g} ]] && groups+=( "${g}" ) > + done < <(printf '%s\n' "${egroups_arr[@]:1}" | sort) > + groups=${groups[*]} > + echo "${groups// /,}" > } Why don't you make groups a scalar variable (i.e., a comma separated list) from the very beginning, if you're converting to it later anyway? local g groups=${egroups_arr[0]} # sort supplementary groups to make comparison possible while read -r g; do [[ -n ${g} ]] && groups+=",${g}" done < <(printf '%s\n' "${egroups_arr[@]:1}" | sort) echo "${groups}" signature.asc Description: PGP signature
[gentoo-dev] [PATCH] user.eclass: Fix egetgroups bash compliance, and make it simpler
Signed-off-by: Michał Górny --- eclass/user.eclass | 10 ++ 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/eclass/user.eclass b/eclass/user.eclass index fdf98caa6099..b237abdda045 100644 --- a/eclass/user.eclass +++ b/eclass/user.eclass @@ -445,11 +445,13 @@ egetgroups() { local egroups_arr read -r -a egroups_arr < <(id -G -n "$1") - local defgroup=${egroups_arr[0]} + local g groups=( "${egroups_arr[0]}" ) # sort supplementary groups to make comparison possible - readarray -t exgroups_arr < <(printf '%s\n' "${egroups_arr[@]:1}" | sort) - local exgroups=${exgroups_arr[*]} - echo "${defgroup}${exgroups:+,${exgroups// /,}}" + while read -r g; do + [[ -n ${g} ]] && groups+=( "${g}" ) + done < <(printf '%s\n' "${egroups_arr[@]:1}" | sort) + groups=${groups[*]} + echo "${groups// /,}" } # @FUNCTION: esethome -- 2.22.0