Hello fellow Linux-fanatics, I am going to start my new series of tutorials on BASH Scripting.

BASH scripting is one of the most sought after skill in a System Administrator. Take it from a System Admin (I mean myself), it comes pretty handy & saves your tons of time, giving you time to watch those cat videos on youtube.

Firstly, Lets talk what is BASH before we move onto scripting.

BASH (short for BOURNE AGAIN SHELL) is program which takes input from user & performs the requested action .

Almost all the Linux distributions have BASH installed  but there are other shells as well like  KSH, CSH, TCSH etc but we are only going to use BASH in our tutorials as it’s the most used shell for Linux.

Here is the picture of how a BASH terminal looks like

Bash terminal scripting

A users default shell can be found in  /etc/passwd file, it’s the last entry on user’s information./etc/passwd

Now lets move to BASH script. In short it is a file (with extension  “.sh”) with series of commands that BASH runs when the script is executed. So any command that you can run directly through BASH terminal, can be put into a script & result will be the same.

But why we need Scripting you ask ?

Answer is simple,  lets think you have some tasks that you do daily like creating tar of 50 folders & copying them to 2 or 3 servers. So rather than executing a tar command 50 times, we will just create a script that will automatically create tar of the folders. & will also copy them to desired locations & what you are doing meanwhile, probably dozing off somewhere.

As mentioned  above , script has an extension “.sh” (for ex We start a script with “#!/bin/bash” as first line which means script is intended to run in BASH. After we are done with script, we give script permission to execute (chmod +x & then we can execute it using any of the below 2 ways:-

  • ./
  • sh

BASH scripting

So that was brief introduction to scripting. Many more tutorials are yet to come, so be prepared. Also , before we actually start writing Scripts, it better to learn some commands which we will be using frequently in our scripts. Links for all the scripting related posts will be mentioned below.

And please also leave us your valuable feedback or queries & I will surely attend them.

If you think we have helped you or just want to support us, please consider these :-

Connect to us: Facebook | Twitter | Google Plus

Become a Supporter - Make a contribution via PayPal

[paypal_donation_button align="left" border="1"]

Linux TechLab is thankful for your continued support.