Bash Tutorial

15 Linux Bash History Expansion Examples You Should Know

by Ramesh Natarajan on August 8, 2011

Bash history is very powerful. Understanding how to effectively use the bash history expansions will make you extremely productive on the Linux command line.

This article explains 15 examples that uses the following bash history expansion features:

  • Event designators – Refers to a particular command in the history. It starts with a !
  • Word designators – Refers to a particular word of a history entry. Typically this gets combined with an even designator. Even designators and word designators are separated by a colon
  • Modifiers – Modifies the result of the substitution done by the event or word designators


12 Bash For Loop Examples for Your Linux Shell Scripting

by Ramesh Natarajan on July 11, 2011

There are two types of bash for loops available. One using the “in” keyword with list of values, another using the C programming like syntax.

This article is part of our on-going bash tutorial series.

This explains both of the bash for loop methods, and provides 12 different examples on how to use the bash for loop in your shell scripts.

Bash has several commands that comes with the shell (i.e built inside the bash shell).

When you execute a built-in command, bash shell executes it immediately, without invoking any other program.

Bash shell built-in commands are faster than external commands, because external commands usually fork a process to execute it.

In this article let us review some useful bash shell builtins with examples.

In bash shell, when you use a dollar sign followed by a variable name, shell expands the variable with its value. This feature of shell is called parameter expansion.

But parameter expansion has numerous other forms which allow you to expand a parameter and modify the value or substitute other values in the expansion process. In this article, let us review how to use the parameter expansion concept for string manipulation operations.

This article is part of the on-going bash tutorial series. Refer to our earlier article on bash { } expansion.

5 Bash Case Statement Examples

by Sasikala on July 13, 2010

Bash shell case statement is similar to switch statement in C. It can be used to test simple values like integers and characters.

Case statement is not a loop, it doesn’t execute a block of code for n number of times. Instead, bash shell checks the condition, and controls the flow of the program.

In this article let us review the bash case command with 5 practical examples.

Looping statements are used to force a program to repeatedly execute a statement. The executed statement is called the loop body.

Loops execute until the value of a controlling expression is 0. The controlling expression may be any scalar data type.

Bash expression is the combination of operators, features, or values used to form a bash conditional statement. Conditional expression could be binary or unary expression which involves numeric, string or any commands whose return status is zero when success.


Bash conditional statements perform different computations or actions depending on whether a programmer-specified boolean condition evaluates to true or false. These statements are used to execute different parts of your shell program depending on whether certain conditions are true. The ability to branch makes shell scripts powerful.