-->

Make an executable Bash Scripts

bash icon

Since I am using Windows Subsystem for Linux (WSL), I have to constantly run the same set of few commands at the start of Ubuntu. I thought of automating them by executing them as a bash script.

Let's see how to create a bash script that can be executed through the command line with a few keystrokes.

1. Create an empty file with .sh extension

create sh file

2. Add #! /bin/bash to the start of the script followed by the commands you want to execute

sample bash script

3. Save the file using CTRL+X and press Y and Enter

The file is not yet executable. You can verify it by executing the ls -lrt command.

file not executable

4. Make the script executable using chmod

chmod to executable

5. Verify executable status using ls -lrt

The filename color will change from white to green to indicate it’s executable.

green color file

6. Execute the script

Use the command ./script.sh

execute bash script