Artificial intelligent assistant

Searching for specific user group membership with an exact match A user has multiple group memberships that contain spaces. Example: * mydomain\staff * mydomain\staff admin * mydomain\staff super User groups can be returned using: id -Gn username | grep -i -o '\bstaff\b' This unfortunately returns a hit if the user is a member of "mydomain\staff admin" or "mydomain\staff super", but not "mydomain\staff". How can I search for just the "mydomain\staff" group membership? * * * As requested, example output from id -Gn username is as follows (all one line): > mydomain\staff mydomain\staff admin mydomain\staff super mydomain\some other group

Since `id -Gn` output is space delimited, you can't use that.

The GNU implementation of `id` since coreutils 8.22 has a `-z` option to output the list nul-delimited instead of space-delimited, so you could do (with GNU `grep` which you seem to be using already):


id -Gzn username | grep -Fxz 'mydomain\staff'


Or:


id -Gzn username | grep -z '\\staff$'


For `staff` in any _domain_ (whatever that is).

Otherwise, if you have a `getent` command, you could take the problem in reverse:


staff_members=$(getent group 'mydomain\staff' | cut -d : -f 4-)
case ",$staff_members," in
(*,username,*) printf '%s\
' 'username is member of mydomain\staff'
esac

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy aa99b5d3be272bd862e4fba9dfb98f1a