Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access non-path WSLENV variable from WSL environment

I'm new to WSL as a development environment, and I'm trying to set some environment variable to begin working on an open source project. In this case, a domain and secret key. I've followed the steps mentioned here https://devblogs.microsoft.com/commandline/share-environment-vars-between-wsl-and-windows/ and here https://medium.com/@kevinv92/how-to-use-wslenv-to-share-environment-variables-between-windows-and-wsl-c06099d5b901 and this is output:

Microsoft Windows [Version 10.0.19041.388]
(c) 2020 Microsoft Corporation. All rights reserved.

C:\Users\kyles>wsl -l -v
  NAME            STATE           VERSION
* Ubuntu-20.04    Running         2

C:\Users\kyles>echo %WSLENV%
MVC_FIREBASE_API_KEY/p:MVC_FIREBASE_DOMAIN/p

C:\Users\kyles>echo %MVC_FIREBASE_DOMAIN%
minimum-viable-ceremonies-dev

C:\Users\kyles>wsl
kylesnowschwartz@DESKTOP-VN55S9F:/mnt/c/Users/kyles$ echo $WSLENV
MVC_FIREBASE_API_KEY/p:MVC_FIREBASE_DOMAIN/p
kylesnowschwartz@DESKTOP-VN55S9F:/mnt/c/Users/kyles$ echo $MVC_FIREBASE_DOMAIN

Nothing is output when for the environment variable, as I am expecting. I would appreciate any help in understanding what I don't understand!

like image 982
Kyle Snow Schwartz Avatar asked Feb 28 '26 14:02

Kyle Snow Schwartz


1 Answers

The Microsoft blog entry is a bit confusing. Fortunately your problem is quite simple: You are using path translation option /p but your environment variable is not a path!

Passing environment variable from Windows to WSL, use /u option:

Microsoft Windows [Version 10.0.19044.1706]
(c) Microsoft Corporation. All rights reserved.

C:\Users\arttu>set MVC_FIREBASE_DOMAIN=minimum-viable-ceremonies-dev

C:\Users\arttu>set WSLENV=%WSLENV%:MVC_FIREBASE_DOMAIN/u

C:\Users\arttu>wsl

$ echo $MVC_FIREBASE_DOMAIN
minimum-viable-ceremonies-dev
like image 78
karttu Avatar answered Mar 03 '26 13:03

karttu