Run Linux Commands on Windows 10: Beyond Bash

Running Linux Applications Directly in Windows 10
Windows 10 incorporates a feature known as the "Windows Subsystem for Linux" (WSL), enabling the execution of Linux applications. Traditionally, access to this functionality is achieved through the Bash shell.
However, it's feasible to execute Linux applications without the prerequisite of initiating a Bash session.
Utilizing the bash -c Command
This capability is made possible by employing the bash -c command. This allows for the execution of Linux commands directly from the Command Prompt and PowerShell interfaces.
Furthermore, it facilitates the creation of desktop shortcuts. These shortcuts can be configured to launch a specific Linux command or program upon activation.
Managing Multiple Linux Environments
Update: For users with multiple Linux distributions installed through WSL, the wslconfig command provides a means to designate a default environment.
Additionally, commands can be directed to run within a particular Linux environment, offering greater control and flexibility.
This allows for streamlined access to Linux tools and applications directly within the Windows 10 operating system.
Executing Linux Commands within Command Prompt or PowerShell
Related information: A guide on installing and utilizing the Linux Bash Shell on Windows 10 is available.
Prior to proceeding, ensure the Windows 10 Bash shell is installed and properly configured. Once completed, a Command Prompt window can be opened and the following command utilized to execute Linux software outside of a Bash environment:
bash -c "command"
For instance, if the intention is to install the emacs package using apt-get, the subsequent command would be entered into a Command Prompt window:
bash -c "sudo apt-get install emacs"
Employing bash -c initiates a Bash shell in the background, subsequently passing the specified command to it for execution. The command will run to completion, terminating both itself and the Bash shell.
All terminal output generated by the executed command will be displayed directly within the Command Prompt window, rather than requiring a separate Bash shell window.
This technique extends to PowerShell, allowing the execution of Linux commands as if they were native Windows executables.
This can be achieved by directly invoking the .exe file, similar to its use in a Command Prompt window, or through any other standard method for executing executables within PowerShell.
bash -c "uname -a"
As with the Command Prompt, the command's output will be presented directly in the PowerShell window. These methods also facilitate the inclusion of Linux commands within batch files or PowerShell scripts.
Executing Linux Commands via the Run Dialog or Start Menu
This method enables the execution of Linux commands not only from the Run dialog but also from the Start menu and various third-party application launchers.
As an illustration, to initiate the vi text editor through the Run dialog, the user should first press the Windows key combined with the 'R' key.
Subsequently, the following command should be entered and executed:
bash -c "vi"
The vi editor will then launch in a dedicated window.
Utilizing the Start Menu
The same principle applies to the Start menu. Typing the command directly into the Start menu search bar and pressing Enter will execute it.
This provides a convenient shortcut for accessing Linux commands without needing to open a dedicated terminal window.
The functionality streamlines workflows and enhances accessibility to Linux tools within a Windows environment.
Executing Linux Commands Through Desktop Shortcuts
Utilizing the bash -c command enables the execution of Linux applications directly from a desktop shortcut. Consider the scenario where you wish to initiate the vi text editor using such a shortcut. The process involves right-clicking on the desktop, selecting New > New Shortcut, and specifying the following as the target:
bash -c "vi"
Saving this shortcut will then allow you to launch vi with a simple double-click.

Further Reading: How to Run Graphical Linux Desktop Applications from Windows 10's Bash Shell
Launching Graphical Applications
This technique extends to launching graphical Linux applications via desktop shortcuts as well. First, an X server must be installed and configured for graphical Linux desktop applications. Following this setup, shortcuts can be created to launch these applications directly.
The command structure for this is as follows:
bash -c "DISPLAY=:0 command"
It's important to note that while Linux commands can be initiated from within Windows, the reverse is not possible. Running Windows software or executables directly from a Bash shell window is not supported.
Related Posts

Touchscreen on Windows PC: Do You Need It?

Find Lost Windows or Office Product Keys - Easy Guide

Windows 10 Resetting Settings: Why It Happens & How to Fix

Monitor FPS in UWP Games on Windows 10 - A Simple Guide
Remove 'Get Windows 10' Icon & Stop Upgrade Notifications
