When you install Ubuntu/WSL, its default shell is Bash. The following is an excerpt from the manual page for Bash that describes its startup script files.

When bash is invoked as an interactive login shell, or as a non-interactive shell
with the --login option, it first reads and executes commands from the file
/etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile,
~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the
first one that exists and is readable.



In the default startup script file layout in Ubuntu/WSL, ~/.bashrc is actually loaded from ~/.profile for login shells.

~/.profile
...
# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi
...



However, the default ~/.bashrc exits immediately if Bash was not invoked as an 'interactive' shell.

~/.bashrc
...
# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac
...



When you open an Ubuntu/WSL console, Bash is invoked as a login shell, and it's considered 'interactive' since you can freely enter commands and get their corresponding result. Hence, if you're planning on starting Linux GUI apps or a desktop environment from an Ubuntu/WSL console, you can add your DISPLAY environment variable to either ~/.profile or ~/.bashrc (you don't need to add it to both).

But if you want to launch your Linux GUI apps directly from Windows Command Prompt or Windows batch files, you should append your DISPLAY environment variable to ~/.profile and make your launching command simpler.

For example, if you've installed Ubuntu 20.04 from Microsoft Store and added your DISPLAY environment variable to ~/.profile, you can try running the following command in Windows Command Prompt or PowerShell to see if your DISPLAY environment variable is ready for the commands you executed through -c (non-interactive) option.

ubuntu2004.exe run "bash --login -c 'env | grep DISPLAY'"



Hence, you can simply execute a command similar to the following example from Windows batch files and directly start a Linux GUI app (ex. xclock).

ubuntu2004.exe run "bash --login -c 'xclock -update 1'"





Share This Story, Choose Your Platform!