I wish to setup different Windows Terminal launch configurations so that I can use bash on WSL in different windows, each with a different environment profile which is configured from the command line - not by adding a new script each time.
Setting up one WSL is easy, I create a Windows Terminal profile which runs bash with my standard .profile with command:
wsl -d Ubuntu-20.04
However my PC has different Linux JDKs, and I wish have Windows Terminal launchers "JDK18", "JDK19" and "JDK20" each to open WSL bash with different profile per JDK.
Currently I can achieve the above using Windows Terminal profile with the command bash.cmd NN, and bash.cmd is this script:
@echo off
rem Runs bash with no PATH from Windows
set Path=
:: Optional arguments are JDKVER:
if x%1 NEQ "" (
set JDKVER=%1
set WSLENV=%WSLENV%::JDKVER
)
rem WSLENV is a list of env variables that are passed from Windows to WSL
C:\WINDOWS\system32\wsl
Because my .profile contains these lines, the correct JDK NN environment variables are setup in the resulting bash:
[[ -z $JDKVER ]] && export JDKVER=20
export JAVAHOME=/mnt/c/linux/jdk-$JDKVER
Is there a way to define the Windows Terminal launcher which bypasses my use of Windows CMD? Example using something which could configure WSL launch with a different environment setting for each profile in needed in Windows Terminal:
wsl -d Ubuntu-20.04 -envvar JDKVER=xxx
...set JDKVER=foo&&...– DuncG Jan 10 '23 at 19:20