Shell is the core part of Linux. It allows you to interact with the Linux kernel by using various commands like cd, ls, cat etc.
Bash is one of the many available shells for Linux. They have mostly common but not identical syntax. Bash is the most popular shell out there and is the default on most Linux distributions.
You open a terminal or SSH session and you have a shell running in it even if you cannot really visualize it.
![linux terminal introduction](https://itsfoss.com/content/images/wordpress/2021/12/linux-terminal-introduction.png)
When you type a command, it is interpreted by the shell. If the command and syntax are correct, it will be executed otherwise you'll see an error.
Why bash scripts when you can just run Linux commands?
You can enter the commands directly in the terminal and they will be executed.
abhishek@itsfoss:~$ echo "hello world"
hello world
And the same can be done in a script as well:
abhishek@itsfoss:~$ cat >> script.sh
#!/bin/bash
echo "hello world"
abhishek@itsfoss:~$ bash script.sh
hello world
Why do you need shell scripts then? Because you don't have to type the same command again and again. You just run the shell script.
Also, if you have complicated logic in your script, typing it all in the terminal won't be a good idea.
For example, if you enter the command below, it will work. But it is not easy to understand and typing it again and again (or even searching for it in the bash history) is a pain.
if [ $(whoami) = 'root' ]; then echo "root"; else echo "not root"; fi
Instead, you can put in a shell script so that it is easier to understand and run it effortlessly:
#!/bin/bash
if [ $(whoami) = 'root' ]; then
echo "You are root"
else
echo "You are not root"
fi
This was still simple. Imagine a complicated script with fifty or a hundred lines!
What will you learn?
There are nine sections in this bash scripting tutorial. You'll learn to:
- Create and run your first bash shell script
- Use variables
- Pass arguments and accept user inputs in your bash scripts
- Perform mathematical calculations
- Using arrays in Bash scripts
- Manipulate strings
- Use conditional statements like if-else
- Use for, while and until loops
- Create functions
Who is the target audience?
Anyone who wants to start learning bash shell scripting.
If you are a student with shell scripting as part of your course curriculum, this series is for you.
If you are a regular desktop Linux user, this series will help you understand most shell scripts you come across while exploring various software and fixes. You could also use it to automate some common, repetitive tasks.
Basically, Bash should be on the learning roadmap of any serious Linux user.
By the end of this Bash Basics series, you should be able to write simple to moderate bash scripts.
All the chapters in the series have sample exercises so you can learn it by doing it.
Prerequisites
If you are absolutely new to the Linux command line, I advise you to get the basics right first.
![](https://itsfoss.com/content/images/wordpress/2021/12/ubuntu-terminal-basic-tips.png)
You should understand how to go to a specific location in the command line. For that, you need to understand how path works in the Linux filesystem works.
![](https://linuxhandbook.com/content/images/2021/04/absolute-relative-path-linux.png)
Next, this tutorial series gives you the basic of directory navigation and file manipulation.
![](https://itsfoss.com/content/images/2023/07/getting-started-with-linux-terminal.png)
Let's begin!