What is the difference between `groups $USER`and `groups` in a terminal?

When I run the the following command in a terminal I get different output. I try to find out if I am a member of the Wireshark group.

groups $USER

Does list wireshark

groups

Does not list wireshark

So do I belong to the Wireshark group or not?


Solution 1:

You haven't restarted per the instructions on that answer.

  • groups is shows groups as currently applied to your user
  • groups $USER is asking the system to calculate the groups for that user.

This isn't a case of "trusting" one over the other. They show pointedly different things.

Groups are applied to a user when they log in. That's why my instructions are to restart or log out then in again. This makes the system apply the new group and thus allows you to use Wireshark.

Solution 2:

From man groups:

Print group memberships for each USERNAME or, if no USERNAME is specified, for the current process (which may differ if the groups database has changed).

I'd trust groups $USER as your current process can return different values.