When using "groups" or "id -Gn", I end up with the typical space-delimited list of all groups for the current user. These commands run on the assumption that group names cannot contain a space character, and indeed, as long as we stay within Unix, it's going to be the case.

However, my company is now part of a bigger one, that has Microsoft domains setups, and unfortunately, their Active Directory domain group names contain a space character, like "FOOBAR\Domain Users".

One of our scripts typically uses "groups" output and makes a list out of it, based on that space-character delimiter, which means that it now fails miserably:

$ groups
FOOBAR\Domain Users FOOBAR\Other Domain everyone admin 

... which obviously ends up producing such list:


As you can imagine, the first 4 groups don't exist and the rest of the script fails to achieve anything of value.

Does anyone know where to obtain such group names in a better way?

PS: I know of /etc/group but such AD groups aren't mentioned there. Would there be another file like this, but for AD groups, that I could parse?

  • 1
    Not sure if it is good "answering practice" to reference an answer on a sister site, but I found this answer on Stack Overflow which deals with spaces in the group names: stackoverflow.com/a/50381984/737427 – Integrator Sep 8 '18 at 15:51
  • 1
    That is indeed exactly what I needed. – chris Sep 9 '18 at 19:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.