The new version of WSL runs a true Linux kernel inside of a virtual machine. This means that any Linux distribution you run under WSL includes Bash.

How to Install WSL and Bash on Windows 11

How to Install WSL and Bash on Windows 11

How to Install WSL and Bash on Windows 11

To install and run Linux operating systems that include Bash on your Windows 11 system, you’ll need to install WSL first. On Windows 11, this is a straightforward process using Windows Terminal. Do not launch CMD (Command Prompt) – Windows Terminal is a different application.

How to Launch Your Linux Distro and Use Bash

How to Launch Your Linux Distro and Use Bash

How to Launch Your Linux Distro and Use Bash

There are two methods you can use to launch your Linux distro. If you installed Ubuntu, you can select the Start menu, type Ubuntu, and select the Ubuntu app to launch it. Alternatively, you can launch the Windows Terminal and just type the command Ubuntu to launch the Linux Bash shell in the Ubuntu environment. To see a list of all available Linux commands you can use in Bash, type help -d. You can get more details about individual commands by typing help followed by the command name. For example, help printf returns command details and information about each command parameter. Some of the more common Bash commands most people use when they first get started include:

Interactive Mode: Type commands into the command-line interface (Windows Terminal). Batch Mode: Run a text file that contains all of the commands you’d like Linux to execute in order. Many people create these scripts using programming syntax.

How to Run a Bash Script in Windows

How to Run a Bash Script in Windows

How to Run a Bash Script in Windows

To run a script in Bash, just create a text file using your favorite file editor like Notepad and save it in a location you’ll remember. One thing that’s unique about a Bash script is that the first line must be “#!” followed by the path of your Linux bash path. To see what that is, launch Ubuntu and type which bash into the command line window. This will provide the Bash path. Create a new text file and include that first line at the top. In the case of this example, that would be: #! /user/bin/bash Follow this line with each sequential command you want Linux to run. In this example:

Line 1: Uses the echo command to display text to the user on the screen. Line 2: Combines echo with the date command to return today’s date. Line 3: Combines echo with the whoami command to return your user name.

Save this text file with a .sh extension. Remember the path to this file. Next, open the Windows Terminal and use the cd command to navigate to the path where you’ve saved the Bash script. To run the script, type bash «name of script». This is a very simple example, but this demonstrates how you can use such a file to craft entire Bash script programs. Even programming statements like IF statements are available to include decision-making capabilities in your script. The site SS64 provides an extensive resource with all available Bash commands that you can use in the Bash terminal or your Bash scripts.You can also see a tutorial on using a Linux shell script to back up a directory.