ldepablo ldepablo - 1 year ago 81
Bash Question

sudo whoami vs sudo echo `whoami`

Simply put, why is this? Wouldn't it make more sense that sudo echo

whoami
returns root too?

Cheers

me:~$ whoami
me
me:~$ sudo whoami
root
me:~$ sudo echo `whoami`
me

Answer Source

This is happening because whoami get substituted prior the sudo and echo. Basically:

sudo echo `whoami`

first becomes

sudo echo me

and then it sudo get executed.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download