BASH in a Nutshell
Introduction
Bash (Bourne Again Shell) is one of the most widely used Unix shells.
Developed as a free software replacement for the Bourne Shell (sh), Bash has become the default shell for most Linux distributions and macOS.
A Brief History of Bash
Bash was created by Brian Fox in 1989 as part of the GNU Project.
Brian intended to create a free alternative to the proprietary Bourne Shell.
Bash was later maintained by Chet Ramey.
Over the years, Bash has evolved, introducing features from KornShell (ksh) and C Shell (csh), making it more powerful and user-friendly.
Bash history:
- 1989: Initial release of Bash (version 1.0).
- 1996: Bash 2.0 introduced command-line editing and improvements.
- 2004: Bash 3.0 introduced arithmetic improvements and enhanced scripting capabilities.
- 2009: Bash 4.0 added associative arrays and better programming constructs.
- 2014: Bash 4.3 became infamous due to the Shellshock vulnerability.
- 2019: Bash 5.0 introduced improved scripting features and performance enhancements.
Getting Started with Bash
Basic Commands
Fundamental Bash commands:
|
|
Writing a Simple Bash Script
Bash scripts are simple text files containing a sequence of commands. Here’s an example:
|
|
Save this file as script.sh
, then make it executable and run it:
|
|
Variables and Conditionals
Bash supports variables and conditional statements:
|
|
Loops in Bash
Bash allows looping through commands:
|
|
Functions in Bash
Bash also supports functions:
|
|