How to Create & Run Shell Scripts on Windows [Step-By-Step]

You will need to enable the Windows Linux Subsystem before creating a script

by Vladimir Popescu
Vladimir Popescu
Vladimir Popescu
Managing Editor
Being an artist his entire life while also playing handball at a professional level, Vladimir has also developed a passion for all things computer-related. With an innate fascination... read more
Reviewed by Alex Serban
Alex Serban
Alex Serban
Windows Server & Networking Expert
After moving away from the corporate work-style, Alex has found rewards in a lifestyle of constant analysis, team coordination and pestering his colleagues. Holding an MCSA Windows Server... read more
Affiliate Disclosure
  • A shell script can help carry out repetitive automated tasks such as backup and software installations via the command line. 
  • It is possible to run a shell script file in Windows using the Windows Subsystem for Linux.
shell script for windows

To fix various PC problems, we recommend Restoro PC Repair Tool:
This software will repair common computer errors, protect you from file loss, malware, hardware failure and optimize your PC for maximum performance. Fix PC issues and remove viruses now in 3 easy steps:

  1. Download Restoro PC Repair Tool that comes with Patented Technologies (patent available here).
  2. Click Start Scan to find Windows issues that could be causing PC problems.
  3. Click Repair All to fix issues affecting your computer's security and performance
  • Restoro has been downloaded by 0 readers this month.

A shell script is a shell programming language program typically used on Linux and another Unix-based operating system. However, you can create and run shell scripts on Windows with additional steps. 

Here in this guide, we have mentioned a step-by-step method to run a shell script on Windows. Let’s get started!

How can I create and run shell scripts on Windows?

1. Install the Windows Subsystem

  1. Press Windows + I to open Settings.
  2. Go to Privacy & Security, and click For developersSettings - Privacy Security
  3. Click the toggle switch next to Developer mode. Now click Yes on the Use developer features window.Developer settings
  4. Press the Windows button and type Turn Windows features. Next, select the option displayed and click OpenWindows features - shell script for windows
  5. Locate Windows Subsystem Linux and place a checkmark next to it. Click OK.Windows Subsystem for Linux
  6. Follow the onscreen instructions and restart your PC to finish. 

2. Download Ubuntu & Integrate it with WSL

  1. Press the Search button and type Microsoft Store.
  2. Launch the store app and type Ubuntu in the search bar.Ubuntu -shell script for windows
  3. Click Ubuntu from the search and click on Get to download it.
  4. Search for the app and launch it.
  5. The Linux command prompt will install on your disk.Ubuntu - shell script for windows
  6. The integration with WSL will also initiate.
  7. Enter the username and password and note it down for future use. The process might take some time to complete. 

3. Create a shell script

  1. Go to the desired location on your computer, press the Shift key, and right-click on the blank space.Powershell  -shell script for windows
  2. From the context menu, click the Open PowerShell window here.
  3. Type the following command to get redirected to the bash shell: bashBash
  4. Next, copy and paste the following command after replacing the filename with the name of your file and press Enter to create a shell script file: cat>filename.shcatscript - create script
  5. Check the created file and go back to PowerShell. Press Ctrl + C to terminate the process. 
  6. To run the shell script, you need to add some data. On the PowerShell window, type the following command after replacing the filename with the name of the file and press Enter. This command will open a file for editing: vi filename.shvi
  7. Press the I key to access the file and start editing it. 
  8. Type the following command in the file: echo “Hello World”Enter -shell script for windows
  9.  To save the contents of the file and close it, press the Esc key from the keyboard and type the following command, and press Enter: wq 

4. Run the Shell Script

4.1 Use the PowerShell

  1. Go to the location where your sh file is present, press the Shift key, and right-click the blank space. 
  2. From the context menu, click the Open PowerShell window here
  3. Type the following command and press Enter to go to the bash shell: bash
  4. Next, copy and paste the following command and press Enter: sh filename.shHello world output -Enter -shell script for windows
  5. You will see the output. 

4.2 Use Command Prompt

  1. Press the Windows key, type CMD and click Open.
  2. Type the following command and replace the E:/New folder with the path of your file, and press Enter: cd /d E:/New folder.
  3. Next, copy and paste the following command, replace the filename with the name of the file, and press Enter: bash filename.shBash output cmd -Hello world output -Enter -shell script for windows
  4. You will get output on your command prompt window. 

 So, these are steps that you can follow to run shell script commands on Windows. Try this step-by-step guide and if you have any questions, let us know in the comments section below.

Still having issues? Fix them with this tool:


If the advices above haven't solved your issue, your PC may experience deeper Windows problems. We recommend downloading this PC Repair tool (rated Great on to easily address them. After installation, simply click the Start Scan button and then press on Repair All.

This article covers:Topics: