This question already has an answer here:
People usually want to preserve their environment variables while executing
sudo for various reasons, but, there are some cases where discarding environment variables makes much more sense. For example, on Ubuntu,
$HOME (along with a few other variables) is carried over to the process spawned as root; however, this makes no sense when trying to use Linux containers.
One could obviously edit
/etc/sudoers to configure this behaviour, but I'd like to keep this behaviour and resort to discarding environment variables only for certain commands. There is a
-H flag, but that is only for
$HOME and doesn't really help in my case since I need to unset all variables.
How should I go about doing this?