Articles

Home / Articles / DevOps / How to create a simple Bash script?

How to create a simple Bash script?

Published on Oct. 14, 2021

Bash scripting is an extremely powerful and useful part of system administration and development. For the beginner, this might seem an extremely scary part, but once you understand the logic you can actually do a lot of things using this.

 

We have already done a lot of discussion on the introduction of shell script, you can find that here - What is Shell Scripting? 

 

In this article, we are going to learn how to create a simple bash script file and add some basic logic there.

 

Table of Content

 

How to create a bash script file?

In order to create a simple bash script file follow the following steps:

  1. Open an editor
  2. Provide the path of your bash script
  3. Write commands
  4. Save the file(generally using .sh extension)

 

As I am working on RedHat 8, so here are my steps:

 

Opening vi(text editor)

 

vi basic.sh

 

File code - 

 

#!/usr/bin/bash  //path of bash interpreter

echo "Hello BrighterBees"

 

How to execute the bash script?

In order to execute the bash script we have the following ways:

 

Using bash command

bash basic.sh  

 

After executing

To run your script file as executable firstly you have to make your file executable. To make the file executable follow the command:

 

chmod +x basic.sh

 

Once the file become executable use the below command to execute that

 

./basic.sh

 

Final Voice

Here is how you can get started with Bash scripting. Try to run different-different commands in your script.

 

To learn more about bash scripting bookmark this page so that you don't miss the future updates.

 

Connect with the author on Twitter

 

···