Windows – PyCharm on Windows 10, how to use WSL ubuntu bash to run shell scripts

bashpythonUbuntuwindowswindows-subsystem-for-linux

I have installed PyCharm Community Edition on Windows 10, my Windows also has WSL Ubuntu installed.

We know that PyCharm on Linux can create and run shell scripts because PyCharm use the /bin/bash on Linux.

But on Windows, PyCharm doesn't know where to find /bin/bash.
So I change the settings on PyCharm on Windows 10.

In File–>Settings–>Tools–>Terminal, change the shell path from cmd.exe to bash.exe.

When this is done, I can run Linux command in the PyCharm terminal like this:
enter image description here

We can see that the file path has been changed to /mnt/c/Users/pcl/PycharmProjects/test-1

The problem is, when I run shell scripts from the PyCharm IDE, it gives this error:
enter image description here

It says, /bin/sh: 0: Can't open C:/Users/pcl/PycharmProjects/test-1/test-1.sh

Of course it can't open C:/Users/pcl/PycharmProjects/test-1/test-1.sh, because the file path has been changed to /mnt/c/Users/pcl/PycharmProjects/test-1 in WSL.

But PyCharm is just not smart enough to recognize it.

So what can I do?(I know run PyCharm in a Linux VM is a solution)

Best Answer

You can specify your interpreter and pass the script as an argument like so:

$sh test-1.sh