2

A similar question has been asked with no satisfying answer. I installed kaldi on WSL and when running a script I get this error, that apparantely has to do with "Program Files".

sh: 1: export: Files/WindowsApps/CanonicalGroupLimited.UbuntuonWindows_2004.2021.222.0_x64__79rhkp1fndgsc:/mnt/c/ProgramData/Oracle/Java/javapath:/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: bad variable name

One of the answers was to make a link "Program" to "Program Files". But, it fails: /mnt/c$ sudo ln -s /mnt/c/"Program Files" Program ln: failed to create symbolic link 'Program' Making the link on the windows side succeeds but has no effect.

user535733
  • 68,493
Adoram
  • 31
  • 1
  • 2

3 Answers3

1

I have a hunch that this is caused by something in your script or startup files (assuming ~/.bashrc or ~/.profile) not properly quoting the PATH variable. Because WSL appends the Windows path to the WSL path automatically, it's adding some path elements with "Program Files" in, which is correct.

But it does require proper variable quoting. Check your script for use of $PATH and quote it (or add the potentially offending lines to your question if you need help with that). If you don't see anything suspect in the script, then also check your ~/.bashrc and ~/.profile.

Edit/update: I'm fairly sure the offending line will be in the script which is being processed through dash (i.e. sh). Bash can handle this just fine without additional quoting:

> export PATH=$PATH:newpath
> echo $?
0
> echo $PATH
> # outputs correct PATH, even with spaces in the Windows path

However, run sh and try the same:

$ export PATH=$PATH:newpath
sh: 1: export: Files/NVIDIA: bad variable name
$ export PATH="$PATH":newpath
$ echo $?
0
$ echo $PATH
# outputs correct PATH, even with spaces in the Windows path

There's also a "bandaid" solution to disable the WSL feature that appends the Windows path to the WSL/Linux path. You can do this by creating (or editing if it already exists) /etc/wsl.conf and adding the following lines:

[interop]
appendWindowsPath=false

Then stop the instance with wsl --terminate Ubuntu (assuming the default distro name), and restart WSL.

It's not a good permanent solution, IMHO, since it makes it far more difficult to run Windows apps (such as VSCode) when they aren't in the path.

Better to figure out the core issue and fix it in the scripts.

NotTheDr01ds
  • 22,082
0

I found the answer in https://arstechnica.com/civis/viewtopic.php?f=16&t=1472885 You need to remove the windows paths from $PATH, and you do that by creating /etc/wsl.conf with the following text: [interop] appendWindowsPath=False Then close the WSL window, wait 8 sec, and relauch.

Adoram
  • 31
  • 1
  • 2
0

I may be a little late to the game here, but posting this in case anyone else stumbles across this thread. I was having this same issue with a fresh install of WSL using Ubuntu, and it was fixed by simply running these commands (as root) in WSL:

$ sudo apt update && sudo apt upgrade -y

All I had to do was restart my WSL terminal after this and the issue disappeared. Hope this helps someone!

th317erd
  • 131