Linux – wsl’ is not recognized as an internal or external command

command linelinuxwindows 10windows-subsystem-for-linux

I installed Windows Subsystem for Linux and turned it on under windows turn ON OFF features. And then restarted my Pc. I did check on cmd soon after restarting the PC by typing "wsl" and it works. But when i run my script from its folder which has the command "wsl -e xxx.sh", i get an error

'wsl' is not recognized as an internal or external command,
operable program or batch file.

Could you guys help me with it please. Thank you.

My PC is running on
Os: Windows 10 Pro;
Microsoft windows version: 1903;
Os Build: 18362.418

Best Answer

The most common reason why a command which runs an executable program works on the command line, but not in a batch script, is that, in the script, prior to the line containing the problem command, the user has created a variable %path%. It might seem a handy name for a variable that holds, well, a path. The problem is that this variable name is used by Windows to hold a semicolon-separated list of folders which are searched when an executable is called. It is a system variable. If you have redefined it, then all executables (e.g. .exe, .bat, .vbs, etc) that Windows uses, will not be found, and the script will fail with exactly this message, where xxx is the program or file that is expected:

'xxx' is not recognized as an internal or external command, operable program or batch file.

This can be confusing because commands which are internal to the cmd environment (dir, cls, set, copy, move, etc) (list here) still continue to work in this situation.

You can debug a script where this is suspected by inserting the path command immediately before a problem line. The Windows path variable starts with these folders, and may be extended as programs are installed:

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem