DEV Community

Cover image for How to run shell scripts in windows
Mathias Jiya
Mathias Jiya

Posted on

How to run shell scripts in windows

Hello there, today's article is about shell scripts. Shell scripts are commands put together in a file to be ran on the terminal in other to perform certain operation(s) by just running a single command in most cases.
Running a shell script on windows can be a little bit tricky though. Here's how to run a shell script on windows:

Assuming our script is in a file named helloworld.sh which contains the following commands

#!/bin/sh

echo "script running..."
echo "hello world"
Enter fullscreen mode Exit fullscreen mode

At this point I know you might be wondering what a Batch(.bat) script is. Well wonder no more ;)
BAT file extension is a Windows batch file. It's a plain text file that contains various commands used for repetitive tasks or to run groups of scripts one after another. Software of all types use BAT files for various purposes—for example, to copy or delete files, run applications, and shut down processes.

  • Create a new file named helloworld.bat (the name of the new file does not matter but I think it makes sense to name it after the original bash file) and paste the copied batch commands into it and save.
  • On the windows power shell, navigate the project folder and run ./helloworld.bat

If everything is done correctly, you should see something similar to this in your windows power shell

"script running..."
"hello world"
Enter fullscreen mode Exit fullscreen mode

Top comments (0)