Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

How do I show default user on WSL?

Writer Olivia Zamora

I see that there is a way to set the default user for a WSL distro using

ubuntu.exe config --default-user FredSanford

But is there a way to view the current default user? I can't seem to be able to dig up anything.

5

1 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).
  • .exe is part is also optional after bash, ubuntu and even wsl.
  • ubuntu command can vary according to the version. For example, if you have installed Ubuntu, command would be ubuntu but for Ubuntu 18.04 and 20.04, it would be ubuntu1804 and ubuntu2004 respectively.

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