Writing a bash script is super easy, and in this tutorial, we will learn how to write our first bash script on a Windows computer.
What is a bash script?
A bash script contains the sequence of commands that a bash program executes. Using a bash script, you can carry out a sequence of operations. For instance, browsing to a certain directory, making a folder, making new files within that folder, and starting a process are all examples of command-line operations.
![](https://bluewindlab.net/wp-content/uploads/2024/07/0_example_of_bash_script.png)
Requirements for bash scripting
Download and install git from this link.
https://git-scm.com/downloads
![](https://bluewindlab.net/wp-content/uploads/2024/07/install_git_on_windows.png)
Now you are ready to write the bash script on your Windows machine. Follow these steps.
1. Open the gitbash terminal on a Windows machine.
2. Go to any folder and write nano bash.sh command to create a new bash file.
![](https://bluewindlab.net/wp-content/uploads/2024/07/2_create_a_bash_file.png)
3. This command will also pop up an editor window.
![](https://bluewindlab.net/wp-content/uploads/2024/07/3_bash_nano_editor.png)
4. The bash script always starts with the #! /bin/bash command. You can write the bash command to get the bash file path.
![](https://bluewindlab.net/wp-content/uploads/2024/07/4_bash_script_print_my_name.png)
5. In this first bash script, I would like to print my name.
6. Pressing ctrl+x and writing y will save the script.
![](https://bluewindlab.net/wp-content/uploads/2024/07/5_save_bash_file.png)
8. To run the script, write bash bash.sh
![](https://bluewindlab.net/wp-content/uploads/2024/07/6_run_bash_script.png)