Issue
I have tried getent, group command, id -Gn $user and some sed combination but I don't think I am able to achieve hence reaching out to fellow programmers.
I want to be able to print this : groups abc123
Output
abc123 : devops build test design
Expected Output
groups:
- devops
- build
- test
- design
Solution
From what I see, you are trying to convert the groups of your user to an yaml
array, try to use:
echo "groups:" ; for i in $(id -Gn myuser);do echo " - $i" ;done
groups:
- users
- lp
- vboxusers
- kvm
You can use too:
echo "groups: [ $(groups myuser | sed -e 's/.\+\s\+:\s\+\(.\+\)/\1/g' -e 's/\(\s\+\)/, /g') ]"
groups: [ myuser, lp, vboxusers, kvm ]
Answered By - c4f4t0r