6

I can understand the commands who and whoami, but what exactly happens when I type:

who am i

and

who am

I am on Ubuntu, nothing happens after them!

Why doesn't Linux / UNIX reply with an error message (something on the line of "unknown arguments" for who), or just reply with the output of who?

4

If whoami doesn’t output anything, it probably indicates that your shell isn’t a login shell. There’s no user associated with who’s standard input, so who doesn’t output anything — that’s not an error as far as it’s concerned, so it doesn’t output an error message.

If you run

xterm -ls

to open a terminal with a login shell, you should find that whoami and who am i work fine. The same goes for a remote login using e.g. SSH.

  • You can also use the login command prior to issuing whoami, who am i or who mom likes etc, there appear to be many more variations in the arguments ;-). – thecarpy Jul 10 '17 at 17:42
4

When you type:

$ who am i

In a shell (any shell), the first word (who) is parsed as "the command".
So, who is searched in the PATH, and after it is found, all other parameters/words/arguments are given to the command as arguments.

It is the job of who to interpret the arguments.

In fact, in linux, the manual of who has this to say about 'am i':

If ARG1 ARG2 given, -m presumed: 'am i' or 'mom likes' are usual.

So, such who will print only "hostname and user associated with stdin" (-m option).

If there is no user associated to stdin, nothing is printed.

1

Unable to replicate:

ghoti@home:~
$ who am i
ghoti    pts/0        2017-07-10 08:33 (38.142.104.170)
ghoti@home:~
$ cat /etc/issue
Ubuntu 16.04.2 LTS \n \l

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.