Books / Introduction to Bash Scripting / Chapter 1
Introduction to Bash scripting
Welcome to this Bash basics training guide! In this bash crash course, you will learn the Bash basics so you could start writing your own Bash scripts and automate your daily tasks.
What is BASH?
Bash is a Unix shell and command language. It written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell and release in 1989. It is widely available on various operating systems, and it is also the default command interpreter on most Linux systems. (BASH used to be the default shell on macOS, however, starting with Catalina, Apple replaced BASH with zsh as the default shell. Bash will still be available.)
Bash stands for Bourne-Again SHell. As with other shells, you can use Bash interactively directly in your terminal, and also, you can use Bash like any other programming language to write scripts. This book will help you learn the basics of Bash scripting including Bash Variables, User Input, Comments, Arguments, Arrays, Conditional Expressions, Conditionals, Loops, Functions, Debugging, and testing.
In order to write Bash scripts, you just need a UNIX-like terminal (like the macOS Terminal application) and a text editor like Sublime Text, VS Code, or a terminal-based editor like vim or nano.
Structure of BASH Scripts
Let’s start by creating a new file with a
.sh extension. As an example, we could create a file called
To create that file, you can use the
Or you can use your text editor instead:
In order to execute/run a bash script file with the bash shell interpreter, the first line of a script file must indicate the absolute path to the bash executable:
This is also called a Shebang.
All that the shebang does is to instruct the operating system to run the script with the