Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 279
ldepablo Avatar asked Sep 12 '25 23:09

ldepablo


1 Answers

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.

like image 71
Andriy Berestovskyy Avatar answered Sep 14 '25 19:09

Andriy Berestovskyy