How do I show default user on WSL?
Olivia Zamora
I see that there is a way to set the default user for a WSL distro using
ubuntu.exe config --default-user FredSanfordBut is there a way to view the current default user? I can't seem to be able to dig up anything.
51 Answer
If you use bash or bash.exe as mentioned by Terrance, you'll be invoking the default WSL distribution in your system which may or may not be Ubuntu or desired version of Ubuntu in case you have multiple distributions or multiple versions of Ubuntu. In those scenarios you can specify the distribution instead of bash or bash.exe, i.e.
ubuntu -c "whoami"This would execute the command in default shell in non-interactive mode, i.e., environment variables won't be available at this stage (for example, SHELL and PATH). You'll get no result if you run
ubuntu -c "echo $SHELL"As an alternative of c option, you can use run as well. From the help page of ubuntu (which can be obtained using ubuntu help):
run <command line> Run the provided command line in the current working directory. If no command line is provided, the default shell is launched.The resultant command would be:
ubuntu run "whoami"Footnotes:
- Enclosing command in quotes is optional. Anyway you should escape the special characters (if used anywhere).
.exeis part is also optional afterbash,ubuntuand evenwsl.ubuntucommand can vary according to the version. For example, if you have installed Ubuntu, command would beubuntubut for Ubuntu 18.04 and 20.04, it would beubuntu1804andubuntu2004respectively.