There seems to be some surmising going on here…
The backticks are obviously doing what others explained, expanding whoami
before invoking 'sudo', and leaving the backticks off return 'root', as expected.
But it's useful to understand what is actually happening with sudo(8). So I actually looked at the man page!
"The real and effective uid and gid are set to match those of the target user…"
So it appears that the observed behaviour has nothing to do with the difference between effective and real user id.
It's also illustrative to do "sudo printenv" and compare to just "printenv," which actually surprised me a bit. It shows that [i]some[/i] exported variables are available and and others are not: it reports the invoking user's HOME, PATH, PS1, SHELL, TERM, and EDITOR, but not others like MANPATH, CVSROOT, LD_LIBRARY_PATH, or ENV. That seems a bit odd, as it could cause programs to behave differently than they do either as the original user, or as root.
whoami
? Just say sudo whoami.. returns root