2

When I do env or printenv I get a bunch of environment variables that has some weirdness associated with them. See below on the top part of the list and you will see a lot of quoted strings.

These I cannot access/print.

It seems as if I can access some of them, but that is only because they have been duplicated. Both WSL_DISTRO_NAME and PWD comes in quoted and unquoted versions, but far from all. Both http_proxy and WSL2_GUI_APPS_ENABLED cannot be echoed. Their values simply do not exist.

'WSL_INTEROP=/run/WSL/21689_interop'
'WSL_DISTRO_NAME=Ubuntu'
'DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus'
'DISPLAY=:0'
'WT_SESSION=0f7a3e3a-1bd3-4a40-9535-267fede5076a'
'http_proxy=http://censored.com'
'USERPROFILE=/mnt/c/Users/my-user'
'WT_PROFILE_ID={51855cb2-8cce-5362-8f54-464b92b32386}'
'WSLENV=WT_SESSION:WT_PROFILE_ID:USERPROFILE/up'
'PULSE_SERVER=unix:/mnt/wslg/PulseServer'
'PWD=/home/my-user'
'TERM=xterm-256color'
'WSL2_GUI_APPS_ENABLED=1'
'XDG_RUNTIME_DIR=/run/user/1000/'
'HTTP_PROXY=http://censored.com'
'WSL_PAC_URL=http://censored.com/wpad.dat'
'WAYLAND_DISPLAY=wayland-0'
'HOSTTYPE=x86_64'
SHELL=/bin/bash
SUDO_GID=1000
WSL_DISTRO_NAME=Ubuntu
XPLATFORM_UTILS=1
SUDO_COMMAND=/usr/sbin/enter-systemd-namespace
SUDO_USER=my-user
PWD=/home/my-user
LOGNAME=my-user
XDG_SESSION_TYPE=tty
HOME=/home/my-user
BASH_D=/home/my-user/.bash.d
LANG=C.UTF-8
WSL_INTEROP=/run/WSL/21689_interop
XDG_SESSION_CLASS=user
TERM=xterm-256color
USER=my-user
BIN_DIR=/home/my-user/bin
DISPLAY=:0
SHLVL=1
XDG_SESSION_ID=92
WSLENV=WT_SESSION:WT_PROFILE_ID:USERPROFILE/up
XDG_DATA_DIRS=/usr/local/share:/usr/share:/var/lib/snapd/desktop
HUSHLOGIN=FALSE
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/GNATSTUDIO/bin:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Program Files/Microsoft VS Code/bin:/mnt/c/Program Files/Alire/bin:/mnt/c/GNAT/2021/bin:/mnt/c/Users/my-user/AppData/Local/Microsoft/WindowsApps:/snap/bin
SUDO_UID=1000
MAIL=/var/mail/my-user
OLDPWD=/home/my-user
_=/usr/bin/env

Any idea how this happens and if/how I can fix it? The practical consequence of this is that I need to parse the list of environment variables from env, split into key/value and re-set them in the shell. A bit unnecessary TBH, but the only way stuff like http_proxy gets set.

❯ npx envinfo --system

  System:
    OS: Linux 5.15 Ubuntu 24.04.2 LTS 24.04.2 LTS (Noble Numbat)
    CPU: (10) x64 13th Gen Intel(R) Core(TM) i7-1365U
    Memory: 12.57 GB / 13.65 GB
    Container: Yes
    Shell: 5.2.21 - /bin/bash

Host is Windows 11 in enterprise.

I might add that this does not happen on the Rocky Linux install I just made, only the default Ubuntu WSL. I have also tried deleting my own .bashrc and .profile files to see if that had any effect. There was none.

2
  • I would be curious about the output you get from the command env | head -1 | od -a . This limits the output from env to the first line and the od command will show the line in a format that can reveal characters that aren't ordinary text. That's the first thing that comes to mind that could make bash wrap quotes around the variable and value like that. Commented Mar 20 at 14:04
  • I wonder if this is actually what's coming through the Kernel. Maybe check to see if they are present with od -a /proc/self/environ. Commented Mar 22 at 23:57

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.