0

Good day,

I has following bash script which returns a list of users. I want them to be echoed as a list not row:

#!/bin/bash
#List the users that are members of root group
gid0=$(grep root /etc/group | sed 's/^root:x:0://' | sed 's/,/\n/g')
#List the users that are sudoers in /etc/sudoers
sudoersU=$(grep "ALL=(ALL)" /etc/sudoers | grep -v '^ *#\|^%' | awk '{print $1"\n"}')
#List the users in group to execute all commands
sudoG=$(grep "ALL=(ALL)" /etc/sudoers | grep -v '^ *#' | grep '^%' | awk '{print $1}' | sed s'/%//g')
for U in $sudoG
do
sudoersG=$sudoersG" "$(grep $U /etc/group | sed 's/^'"$U"':x:[0-9]*://' | sed 's/,/\n/g')
done
all=$(echo -n $gid0 "" ; echo $sudoersU "" ; echo $sudoersG)
#sort unique two variables
allsortuniq=$(echo "$all"|tr " " "\n"|sort|uniq)
echo $allsortuniq

I cannot turn $allsortuniq to list.

Many thanks

Archie
  • 115
  • 1
  • 3
  • 10

0 Answers0