In the latest Win 10 Creator Update, Bash Shell allows running binary files and standard Windows CMD commands. You can run both Linux and Windows programs on Bash Shell of Windows 10 or combine Windows commands into Bash code.
If you're not familiar with launching Command Prompt, also known as CMD, readers can refer to Mytour's guidance on how to start CMD right here.
Guide to Running Programs on Bash Shell in Windows 10
Things to know:
- User Account: Programs launched from Bash Shell will run like programs launched from Windows.
- Permissions: These programs will have similar access rights to the Bash.exe process. If you want to run these programs with admin rights, run Bash.exe with admin privileges.
- Working Directory: Programs will have a working directory similar to Bash.exe. Therefore, if you run a command to list the contents in the current directory, the result will be the working directory of Bash.exe. You can also change the working directory using the cd command.
Guide to Running a Windows Program
To execute a Windows program, you need to enter the path to the .exe file of the program in the Bash window. Remember, the C: hard drive partition always corresponds to /mnt/c in Bash commands. Commands in Bash need to clearly distinguish between uppercase and lowercase letters.
Example: Running the Ping utility on Windows using Bash
Type the command: /mnt/c/Windows/System32/PING.EXE
This command is not functioning due to a formatting issue, please retype the correct command.
Running these programs may become a bit more complicated if the program path contains spaces or special characters. In such cases, you need to prefix '' before special characters or spaces.
For example, if you want to run Internet Explorer with the path C:Program Files (x86)Internet Exploreriexplore.exe, the command would be:
/mnt/c/Program Files (x86)/Internet Explorer/iexplore.exe
Guide to running arguments within a command
Bash shell directly executes arguments within a command.
Example: To check the ping of the address example.com, you would type the command:
/mnt/c/Windows/System32/PING.EXE example.com
Or if you want to open the Host file of Windows with Notepad, you would type the command:
Guide to running built-in commands
Some Windows commands are not compiled into .exe files but are integrated into the command prompt (cmd).
For example: The dir command can be executed normally in Command Prompt. To run this command, you need to run it alongside the CMD program. Specifically, you type the command:
Guide to adding directories to the path
Windows Service for Linux environment executes Windows programs similarly to Linux programs. This means you can directly add directories containing .exe files to the path and then execute the .exe files directly. For example, to add the System32 directory to your path, you type the command:
export PATH=$PATH:/mnt/c/Windows/System32
then you can directly run the .exe files with commands like:
Guide to redirecting the output of a command
The output of a Windows command can be 'grouped' into a Linux command. For instance, on Windows, the command ipconfig.exe –all will list details about your active connections; on Linux, the grep command will search the output of the Windows command.
To list detailed connections and search for information about the IPv4 Address, you would type the command:
Here are some basic commands when operating on the Windows 10 Bash Shell. While working and performing operations on it, you can compile and create a script for operations on both Windows and Linux. You can also use the 'bash-c' command from bash commands within the Command Prompt window itself.
These new features are only available on Windows 10 Creator Update, not on Windows 10 Anniversary. Therefore, if you want to experience them firsthand, you can sign up to become a Windows Insider Program user or use Windows 10 Insider with a virtual machine that doesn't affect your system through Hyper-V virtualization. Refer to how to use Windows 10 Insider following the instructions.
