Bash Tutorial – Learn Bash Shell Scripting

Bash is a Unix Shell. Using Bash commands we can write applications for Linux OS.


Bash Script

Bash Script is a file with commands that can be run from Linux Terminal.

Bash Tutorial

Bash Tutorials

With the help of these Bash Shell Scripting tutorials, we shall learn bash scripting. Little understanding of the Linux file system and terminal commands would be helpful to get started with these tutorials.


Bash Scripting Basics

In these series of basic bash tutorials, we shall introduce you to some of the bash fundamentals.

Bash – Script example
Explanation about the basic components of a bash script file

Bash – File extension
Know about the file extension for a bash script and the syntax required to tell the Operating System that a file is bash script.

Bash – echo
Basic Bash Command to echo a string or variables to the terminal.

Bash – Variables
Variables are used to store data. This tutorial describes bash variables and local bash variables with syntax, usage, and examples.

Bash – Command line arguments
User can pass arguments while running the script file. This tutorial explains how to work with arguments.

Bash – Read user input
Prompt for input and read input from user via terminal.

Bash – Read username and password
Learn to read password without echoing back the actual password to a Linux terminal.


Bash Operators

In the following tutorials we cover different kinds of operators, in detail with examples .

Bash Operators

Bash – Arithmetic Operators
Examples and usage demonstration of arithmetic operators in bash scripting.

Bash Relational Operators

Bash Conditional Operators+

More on Bash Operations

Bash Addition
Arithmetic addition operation using arithmetic expansion, the expr command, and the let command.

Bash – Add Numbers from stdin
Examples to read numbers from stdin and add them using Bash script.

Bash – Floating Point Addition
Floating-point addition using external tools like bc (Basic Calculator) or awk.

Bash Subtraction
Subtraction in Bash scripting with various methods like arithmetic expansion, expr, let, and bc for floating-point numbers.

Bash Multiplication
Multiplication in Bash using arithmetic expansion, expr, let, and bc for floating-point numbers.

Bash Division
Division in Bash using arithmetic expansion, expr, and bc for floating-point division

Bash Modulo
Syntax and practical examples for performing remainder calculations using arithmetic expansion and expr.

Bash Increment
Increment variables in Bash scripting using arithmetic expansion, let, and expr commands

Bash Decrement
Decrement variables in Bash using arithmetic expansion, let, and expr commands


Bash Conditional Statements

Conditional Statements help to branch out the program execution based on the value of an expression. Following are some of the bash tutorials that provide a broad understanding of conditional statements that can be used in bash scripting.

Bash If
Introduction to conditional statements with if statement. Contains syntax and examples.

Bash If-Else
Going a step deeper into two-level branching of program control.

Bash Else-If
Multiple branching conditions in a single statement.

Bash Case statement
Executing a specific set of statements based on the value of a variable or an expression.

Additional

Bash If AND Use AND logical operator in If statement’s condition to join two or more simple conditions.

Bash If OR Use OR logical operator in If statement’s condition to join two or more simple conditions.

Bash If NOT Use NOT logical operator to invert the condition in If statement.


Bash Loops

Bash For loop
For Loop statement helps to execute a set of statements for each member of a data set or a derived data type variable.

Bash While loop
Repeat a set of statements based on an expression.

Bash Until loop
This is a little variation to while loop, but it is handy.


Bash Strings

Bash String Programs
Some of the commonly used string operations with examples.


Bash Functions

Functions help to wrap a logical piece of a task as a functionality that could be called.

Bash Functions
A basic introduction to functions in Bash Scripting.

Bash Override commands
This is interesting. You can override the built-in commands with your own set of statements.


Bash Arrays

Arrays are used to store multiple elements in a single container. Elements can be accessed using the index.

Bash Array
Introduction to initialize an array and access elements of it in bash scripting.


Bash File Operations

Bash Read File
Example bash scripts to read contents of a file.

Bash Read File Line by Line
Example bash scripts to read contents of a file (like text file) line by line.

Bash – Write to file
Example bash scripts to write data to a file.

Bash – Check if file exists
Bash script to check if the file exists.

Bash – Check if file is a directory
Bash script to check if the file is a directory.

Bash – Check if file is readable
Bash script to check if the file is readable.


Error Handling in Bash Scripts

Introduction to Error Handling in Bash
An overview of error handling techniques in Bash scripting.

How to use Exit Status Codes in Bash Scripts
Learn how to interpret and use exit codes to manage errors in scripts.

Trap command to Catch Errors in Bash
Guide on using the `trap` command to catch and respond to errors.

Log Errors in Bash Scripts
Techniques to log error messages and monitor script performance.

Retry Logic for Failed Commands in Bash
Implementing retry mechanisms for commands that may fail intermittently.

Bash Programs

Bash – Factorial Program