Who is the user behind `sudo` and how to get the group(itself) which a file belongs?

Hi ! @entity .

You can apply the @James-Carroll suggestion, or ignore the -u option in the set -uo pipefail command.

By the way, the fact that the -u option is activated and that the environmental variable $SUDO_USER appears in your code, without preceding the execution of your program with sudo it will inevitably crash (without some measurements), because the existence of the environmental variable $SUDO_USER is intrinsic to the sudo command.

As for how to find the group (the group itself) to which a file belongs, you can use the Linux command stat.

1 Like