11

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?

2 Answers 2

8

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.

1
  • 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
    Commented Jul 10, 2017 at 17:42
6

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .