When I run bash.exe in Git for Windows from WSL bash, I want to pass PATH from WSL to Win32, and filter out //wsl$/***
items in Win32 bash scripts. So I tried echo ${PATH//\/\/wsl\$+([^:]):/}
but it takes several seconds to run.
My Win 10 is v1903 x64, WSL bash is from Ubuntu, and Git for Windows is v2.22.0.windows.1 . My CPU is Intel E3-1230 v5 .
The below is how I get a $PATH including //wsl$ :
- open WSL bash, modify $PATH and export it
- run
WSLENV=PATH/l start2.exe /d/Git/usr/bin/bash.exe
to get a new console window of bash.exe in Git for Windowsstart2.exe
is a tool of mine just to run exe in another console
echo $PATH
shows something like/mingw64/bin:/usr/bin:/d/Program Files/nodejs://wsl$/Ubuntu/mingw64/bin:...
But in my computer, access to //wsl$/Ubuntu/***
is denied after once system upgrading. So I need to remove these //wsl$/*
items from $PATH, otherwise the bash.exe seems to run slowly.
I tried export PATH="$(echo "$PATH" | sed -r 's|//wsl[^:]+:||g')"
and it worked, but I want to use built-in commands to do so (the code below has been edited):
shopt -s extglob
if [[ $PATH == *//wsl\$* ]]; then
PATH=${PATH//\/\/wsl\$+([^:]):/} # this line takes seconds
fi
I expect it runs quickly, but the code above is very very slow.
Added:
The main problem is my PATH
is dynamic in WSL bash, and can even be changed by myself, so I can not pre-set a constant PATH for Git for Windows's bash.