Windows 10 includes an underlying “Windows Subsystem for Linux” to run Linux applications, but it’s only accessible via the Bash shell. However, there is a way to run Linux applications without first launching a Bash window.
This is possible thanks to the
bash -c command. Use it to run Linux commands via Command Prompt and PowerShell, or even create a desktop shortcut that runs a Linux command or program when launched.
Update: If you have multiple Linux environments installed, you can use the wslconfig command to choose the default Linux environment. There’s also a way to run commands in specific Linux environments.
How to Run Linux Commands in the Command Prompt or PowerShell
RELATED: How to Install and Use the Linux Bash Shell on Windows 10
Before you do any of this, you’ll need to install and set up Windows 10’s Bash shell. After you do, you can open a Command Prompt window and run the following command to run Linux software outside a Bash window:
bash -c "command"
For example, let’s say you wanted to install the emacs package via apt-get. You’d run the following command in a Command Prompt window:
bash -c "sudo apt-get install emacs"
When you use bash -c, Windows will launch a Bash shell in the background and pass the command to it. The command will run until it’s done and then quit, along with the Bash shell. Any terminal output the current command runs will appear directly in the Command Prompt window, rather than a separate Bash shell window.
This trick also allows you to run Linux commands in PowerShell, just as you’d run a normal Windows executable. You can do this by directly running the .exe file as you would in a Command Prompt window, or via any other method for running executables in PowerShell.
bash -c "uname -a"
As with a Command Prompt window, the output of the command will appear directly in PowerShell. These methods can be used to add Linux commands to a batch file or PowerShell script, too.
How to Run Linux Commands From the Run Dialog or Start Menu
This trick also works for running commands from the Run dialog, Start menu, or any third-party application launcher.
For example, to launch vi from the Run dialog, you’d press Windows+R on your keyboard and then run the following command:
bach -c "vi"
The vi text editor will appear in its own window.
This also works for the Start menu, so you can type the same command directly into the Start menu and press Enter to run it as a command.
How to Run Linux Commands with a Desktop Shortcut
bash -c command also makes it possible to launch Linux applications via a desktop shortcut. For example, let’s say you wanted to launch the vi text editor through a desktop shortcut. You’d right-click the desktop, point to New > New Shortcut, and enter the following target:
bash -c "vi"
You can now save the shortcut and it will launch vi when you double-click it.
RELATED: How to Run Graphical Linux Desktop Applications from Windows 10's Bash Shell
Interestingly enough, this trick also works for launching graphical Linux applications from a desktop shortcut. Install an X server and set up graphical Linux desktop applications. You should be able to create shortcuts to launch them directly.
However, you’d have to launch them like this:
bash -c "DISPLAY=:0 command"
While you can launch Bash commands from elsewhere in Windows, there’s no way to run Windows software or executables directly from a Bash shell window.
- › How to Run Windows Programs from Windows 10’s Bash Shell
- › How to Set Your Default Linux Distribution on Windows 10
- › Everything You Can Do With Windows 10’s New Bash Shell
- › How to Use Zsh (or Another Shell) in Windows 10
- › How to Install and Use the Linux Bash Shell on Windows 10
- › How to Enable Dark Mode in Real Life
- › Bing Chat AI Now Has Better Search and Higher Limits
- › Fix: “Message Has Not Been Downloaded From the Server” on iPhone