With "Whoami" I get the user's name through the terminal Ctrl + Alt + T, but with bash it has root.
#! / bin / bash
usr = $ (whoami)
But through bash it gives me root and not the current username.
Please help me!
[Solved] How to get domain user name. User whoami
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Topics in this forum are automatically closed 6 months after creation.
[Solved] How to get domain user name. User whoami
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Re: How to get domain user name. User whoami
That means you're running your script with sudo. Is that needed?
In that case you can use the environment variable $SUDO_USER, it will have the name of the user that invoke
Reliable way in bash is to test if $EUID equals 0 (zero). If so, your script is running as root. In that case use the $SUDO_USER variable for the username. Otherwise (user is running your script as themselves) you can use $USER variable.
In that case you can use the environment variable $SUDO_USER, it will have the name of the user that invoke
sudo yourscript.sh
. This variable is set by sudo.Reliable way in bash is to test if $EUID equals 0 (zero). If so, your script is running as root. In that case use the $SUDO_USER variable for the username. Otherwise (user is running your script as themselves) you can use $USER variable.
Re: How to get domain user name. User whoami
Thank you.
I have another problem. I want to access the desktop taking into account the current user, but it returns me:
domain \ user, when it should be: domain / user
The problem is the backslash.
I have another problem. I want to access the desktop taking into account the current user, but it returns me:
domain \ user, when it should be: domain / user
The problem is the backslash.
Re: How to get domain user name. User whoami
Re: [Solved] How to get domain user name. User whoami
Thank you, xenopeek, Kyowash and lmuserx4849!