I have a little problem in Centos 7 with the command whoami
in a script
for bash the code is as follows:
function comprobar_root(){
if [[ "$(whoami)" != "root" ]];
then
echo -e "\e[91mERROR EJECUTA EN MODO ROOT\e[39m"
exit
else
menu
exit
fi
}
The main problem is that when I put sudo ./programa.sh
it I get to run it in root mode , I have also tried su - y
logging into root but it still gives me the problem instead of jumping to the menu function I get the echo
and it exits the script
.
Thanks in advance.
Command
whoami
on LinuxThe command
whoami
is used in both the Unix operating system and the Windows operating system ."who"
,"am"
,"i"
likewhoami
.-un
.The first versions were created in 2.9 BSD as a convenient way for who am I, the Berkeley Unix that controls the way to print only the identity of the connected user. The GNU version was written by Richard Mlynarik and is part of the GNU Core Utilities (coreutils).
The commands related to the whoami command are the following:
w - Shows who is logged in and what they are doing.
who Reports which users are logged into the system.
It will be because the command is whoami and not whohai