In Ubuntu Server 16.04, when I type who am i
it returns an output similar to who -m
:
user@UbuntuServer:~$ who am I
user pts/1 2018-05-09 00:30 (192.168.1.100)
user@UbuntuServer:~$ who -m
user pts/1 2018-05-09 00:30 (192.168.1.100)
In my Ubuntu Desktop 16.04 who am i
and who -m
do nothing. How do I make this work?
- I found only this related question: What does the command 'set `who am i` do in Linux?
- Also I read
man who
, but couldn't understood how to fix this.
What I actually want is to parse the output of who -m
(who am i
) within a script when this script is executed by sudo
to find the username of the user that runs the script:
user@UbuntuServer:~$ cat who.sh
#!/bin/sh
whoami
echo $USER
who -m | awk '{print $1}'
user@UbuntuServer:~$ sudo ./who.sh
root
root
user