How to find the username in Bash?

I'm starting out on some Linux bash scripting and I'm trying to get the username so I can cd to that user's Desktop:

cd /home/$(user I'm currently using)/Desktop

The code should be similar to the above to my understanding. What kind of terminal command would return just the name of the user I'm using?

4 Answers

The command you were looking for is whoami.

0

You're probably just looking for cd ~/Desktop.

0

See Here

[max@localhost ~]$ echo $USER

max

This will print the name of the user who currently logged in the terminal

[max@localhost ~]$ su -

Password:

[root@localhost ~]# echo $USER

root

who is the command for you which is a shortform for whoami

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like