BASH Script Tutorial

Bash is a command line interpreter (CLI) that allows you to run commands or scripts on Linux systems. Bash is also known as the Bourne Again Shell. It was originally developed at AT&T Bell Labs in 1984 and released under the GNU General Public License.

Linux Tutorial - Linux Concept

It is widely used across various platforms such as Mac OS X, Windows, Unix/Linux, etc. It has become very popular because of its simplicity and ease of use.

Here, in this tutorial you will learn everything about Bash Scripting in 10 Units:

  1. Introduction & Local environment setup
  2. Linux filesystem, Linux Permission schema & File Manipulation
  3. Variables and User Input
  4. Error checking and Handling
  5. Regular Expression
  6. Conditional testing and Scripting Loop
  7. Using Pipe and Redirection
  8. Bash Functions
  9. Scheduling and Logging
  10. Parsing Bash script arguments, Bash parameter substitution and expansion

Tips and Tricks with cheat sheet


Bash script Introduction & Local environment setup

Before we start learning how to write a simple Bash script, let us first understand what exactly a Bash script is.

Here, in this section you will learn basics about bash script and also get the information to setup the local environment for bash script practice.

Learn Filesystem - Linux Concept

Linux filesystem, Linux Permission schema & File Manipulation

In this section, you will learn all about Linux file system, Linux permission schema and basic file manipulation which helps you a lot at the time of writing bash script for files operation.

You will also learn how to create directories and files in Linux to implement those operation using your scripts.

Learn Variable and User input - Linux Concept

Variables and User Input

This section deals with variables and user input. Here, you will learn different types of variable like String, Integer, Float, Boolean, Array, Dictionary, List, Set, etc.

Also, you will learn how to read user input through command line interface.

Learn error checking - Linux Concept

Error checking and Handling

In this section, you will learn error handling in Bash script. This will help you to handle errors while running any bash script.

You will also learn some useful functions to check if a string contains another string or not.

Learn Regular Expression - Linux Concept

Regular expression

In this section, you will see regular expressions. A regular expression is a pattern matching language.

You can use regular expressions to match strings within text. For example, you can search for a particular word in a sentence. The syntax of regular expressions is similar to C-like languages.

Learn Conditional Testing - Linux Concept

Conditional testing and Scripting loop

In this section, you will learn conditional testing and scripting loop. These are two important concepts in bash script. You will learn how to test whether a condition is true or false. 

You will learn also to execute set of code several time till the condition not get satisfied. In this way, you can do something until the condition gets satisfied.

Learn Pipe and Redirection - Linux Concept

Pipe and Redirection

In this section, you will learn pipe and redirection. Pipes allow data from one program to be passed to another program as an output. Redirections allow data to be sent to a file instead of being displayed on the screen.

Here, you will learn how to use these concept into your script to do long operation in single command on in small script.

Learn Functions - Linux Concept

Bash Functions

In this section, you will learn about bash function. A bash function is a block of code that is executed when it is called.

It has its own scope and variables defined inside it cannot be accessed outside.

You will learn here how to define and call a bash function.

Learn Scheduling and logging - Linux Concept

Scheduling and logging

In this section, I will explain you about scheduling and logging.

Scheduling means setting up a task to run at a certain time. Logging is used to record events.

Logging is very helpful in debugging problems.

In this tutorial, you will learn how schedule tasks and log events.

Learn Parameter and Arguments - Linux Concept

Parsing Bash script arguments, Bash parameter substitution and expansion

Arguments are the values given by the users to your script. They may contain spaces, tabs, newlines, quotes, backslashes, etc.

Parameter substitution is a process where the value of a variable is replaced by the contents of another variable.

Expansion is the process of replacing occurrences of special characters (such as $) with their corresponding values.

In this section, you will learn these concepts to use in your script.

Learn Tips and Tricks - Linux Concept

Tips and Tricks with cheat sheet

This section will give you tips and tricks to make your life easier. This is a bonus section to use shortcut to do your operation. I request you to don’t use it before learning above section otherwise it will make you script kid not expert.

Satish Kumar

Satish Kumar


Kumar Satish started his career as a Unix and Linux System Engineer in 2011. Kumar has professiona experience with CentOS, RedHat, Ubuntu, and Debian. He enjoys teaching others how to use and exploit the power of the Linux operating system.