Where do I find the SUDO_COMMAND environment variable?

I'm currently learning the foundations of Linux with Ubuntu and there is a little activity where I need to find information about environment variables. I already found 6/7 info but just can't find SUDO_COMMAND. this is how the list goes:

SHELL=/bin/bash
USER=student
SUDO_COMMAND=
PWD=/home
HOME=/home/student
LOGNAME=student
OLDPWD=/home/student 

I noticed that the information comes in order and the SUDO_COMMAND is between user and pwd. did I make a mistake somewhere?


Solution 1:

SUDO_COMMAND is an environment variable set by sudo only in the environment of the process started by it (and inherited by any child processes). If you run sudo some-command arg1 arg2, then SUDO_COMMAND will contain the absolute path to some-command, and arg1 arg2. If you ran sudo -s or sudo -i, then the variable will be set to the shell that was started. In any case, you probably won't see it outside of a process tree started by sudo.

For example:

$ sudo sh -c 'echo $SUDO_COMMAND'
/bin/sh -c echo $SUDO_COMMAND

Or:

$ sudo env
HOME=/home/muru
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
TERM=xterm-256color
LANG=en_US.UTF-8
LC_NUMERIC=en_GB.UTF-8
LC_TIME=en_GB.UTF-8
LC_MONETARY=en_GB.UTF-8
LC_PAPER=en_GB.UTF-8
LC_NAME=en_GB.UTF-8
LC_ADDRESS=en_GB.UTF-8
LC_TELEPHONE=en_GB.UTF-8
LC_MEASUREMENT=en_GB.UTF-8
LC_IDENTIFICATION=en_GB.UTF-8
MAIL=/var/mail/root
LOGNAME=root
USER=root
USERNAME=root
SHELL=/bin/bash
SUDO_COMMAND=/usr/bin/env
SUDO_USER=muru
SUDO_UID=1000
SUDO_GID=1000

I noticed that the information comes in order

I don't know which command you're using, but you cannot rely on the output of set, declare, env or printenv to be in some order.

Solution 2:

The SUDO_COMMAND is an environment variable which Set to the command run by sudo.

As mentioned by @muru - if sudo execute a new shell - this environment variable will be shown in this new shell

More info

man sudo provides the following details:

ENVIRONMENT
 sudo utilizes the following environment variables.  The security policy
 has control over the actual content of the command's environment.

 EDITOR           Default editor to use in -e (sudoedit) mode if neither
                  SUDO_EDITOR nor VISUAL is set.

 MAIL             Set to the mail spool of the target user when the -i
                  option is specified or when env_reset is enabled in
                  sudoers (unless MAIL is present in the env_keep list).

 HOME             Set to the home directory of the target user when the -i
                  or -H options are specified, when the -s option is
                  specified and set_home is set in sudoers, when
                  always_set_home is enabled in sudoers, or when env_reset
                  is enabled in sudoers and HOME is not present in the
                  env_keep list.

 LOGNAME          Set to the login name of the target user when the -i
                  option is specified, when the set_logname option is
                  enabled in sudoers or when the env_reset option is
                  enabled in sudoers (unless LOGNAME is present in the
                  env_keep list).

 PATH             May be overridden by the security policy.

 SHELL            Used to determine shell to run with -s option.

 SUDO_ASKPASS     Specifies the path to a helper program used to read the
                  password if no terminal is available or if the -A option
                  is specified.

 SUDO_COMMAND     Set to the command run by sudo.