In this article we will cover the commands
As the name implies, orders
whoami It will print the user ID name. In other words, it displays the name of the user who is currently logged in.
How to use the whoami
The syntax for the whoami command is as follows:
To display the name of the user who is currently logged into the system, type the command
whoami Without any options:
The output will display the name of the currently logged in user or request commands. The whoami command can be used in shell scripts to verify the name of the username running the script.
Here is an example of using an if statement to compare the name of the username running the script against the specified string.
if [[ "$(whoami)" != "any_name" ]]; then echo "hanya user 'any_name' yang bisa menjalankan script ini." exit 1 fi
If the username does not match the specified string, the script will pop the echo and exit section.
whoami Also useful for checking username after switching to another user with command
whoami does not accept arguments. If you use arguments, whoami command will print an error output like:
whoami: extra operand ‘anything’ Try 'whoami --help' for more information.
whoami Only two options are accepted:
--help– Displays help messages and exits.
--version– Displays program version and output information.
Run the commands
id With options
-un It will yield the same output by running a whoami:
id To get more information about a specific user.
$USER Contains the name of the currently logged in user:
whoami Is a combination of the word “who am I? It prints the username associated with the current effective user ID. This is very important for a Linux system administrator to manage the operating system.