I use WSL2, and need an environment variable called DISPLAY
to communicate with XServer which is running on my host (windows) IP.
I am trying to set this environment each time my shell starts using my .bashrc
. It has to update each time because my IP is dynamically assigned.
Here is the section of the code in the .bashrc
responsible for setting the DISPLAY
environment variable.
alias windowsip="ipconfig.exe | grep IPv4 | cut -d: -f2 | head -1 | sed 's/^[ \t]*//;s/[ \t]*$//'"
WINDOWSIP="$(windowsip)"
ENDING=":0.0"
export DISPLAY="$WINDOWSIP$ENDING"
Although the .bashrc
runs quietly, there are a number of things that indicate that the environment variable was not set as desired.
Firstly,
bensmus@BENSMUSPC:~$ $DISPLAY
:0.0: command not found
bensmus@BENSMUSPC:~$
This is strange because my windowsip
command works fine, and gives output without any leading spaces.
bensmus@BENSMUSPC:~$ windowsip
123.123.1.23
bensmus@BENSMUSPC:~$
(Note: My ip is not 123.123.1.23, I just feel weird about sharing my IP)
Even more strangely, when I do
bensmus@BENSMUSPC:~$ echo $DISPLAY
:0.0123.1.23
What the heck is going on?
I really want it to just be
bensmus@BENSMUSPC:~$ echo $DISPLAY
123.123.1.23:0.0