su should be an option, too. For example:
su -pg group1 -c $'ps -eo \'user,group,args\' | grep qbittorrent' "${USER?}";
Some might say it's usually more available if compared to alternatives, including sudo, doas, or gosu.
su - run a command with substitute user and group ID ...
su [options] [-] [user [argument...]]
... su allows commands to be run with a substitute user and group ID.
When called with no user specified, su defaults to running an interactive shell as root. When user is specified, additional arguments can be supplied, in which case they are passed to the shell.
... This version of su uses PAM for authentication, account and
session management. Some configuration options found in other su
implementations, such as support for a wheel group, have to be
configured via PAM.
su is mostly designed for unprivileged users, the recommended solution for privileged users (e.g., scripts executed by root) is to
use non-set-user-ID command runuser
that does not require
authentication and provides separate PAM configuration. If the PAM
session is not required at all then the recommended solution is to use
command setpriv
. ...
-c, --command=command
Pass command to the shell with the -c option. ...
-g, --group=group
Specify the primary group. This option is available to the root user
only.
-G, --supp-group=group
Specify a supplementary group. This option is available to the root
user only. The first specified supplementary group is also used as a
primary group if the option --group is not specified. ...
-m, -p, --preserve-environment
Preserve the entire environment, i.e., do not set HOME, SHELL, USER or LOGNAME. This option is ignored if the option --login is specified.
Source: https://man7.org/linux/man-pages/man1/su.1.html or man su
.
Related: https://redd.it/l6y7nv (Is doas a good alternative to sudo?...)