>>>>> 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}"

Attachment: signature.asc
Description: PGP signature

Reply via email to