Introduction
If you use Linux Operating System, it is implied that you must have used Shell Scripting. But do you know what makes it popular?

This is because Shell Script can save you a huge amount of time. You can completely automate hectic repetitive tasks. You can send your work to others to provide them with a script. These scripts perform System-level tasks, Data Backup, Programming, Automation, and Application related tasks. This must have generated an urge to learn more about Shell Scripting.

The article will discuss the foundation of Shell Scripting. This includes its various aspects and basic terminologies. So, without further ado, let’s get started.
Shell Scripting
Before starting with Shell Scripting, ensure you have a Linux Operating System. Examples of Linux Operating Systems are Ubuntu, Devian, Fedora, Deepin, etc. Also, you are good to go if you have macOS or Windows 10. This is because nowadays, MacOS and Windows 10 also support shells.
So, first of all, what is a Shell?
A UNIX shell interprets user commands directly entered by the user or read from a file called the shell script or shell program. It is important to note that shell scripts are interpreted and not compiled. This means the shell processes the command a single line at a time. It differs from C or C++ programs translated entirely into a binary image through a compiler.
A Shell program may be very simple, containing a few shell commands, or quite complex, consisting of thousands of shell commands.
Characteristics of Shells
Some common characteristics of Shells are mentioned below. Note that it is not compulsory for Shells to checklist all the characteristics.
- A Shell can be made using a text editor of your preference.
- A Shell program is executed similarly to Shell commands. You only need to type the program's name along with Enter key.
- A Shell program is a simple program consisting of primitive shell commands.
- Shell programs are in free format. That means a program is correct if its shell commands follow the syntax. You can use blank lines, indentation, and whitespace freely.
- Like any other program, shell programs allow input and output, logical decision-making, file creation and deletion, and system calls.
- Shell programs have permission modes similar to any other file. You must have correct permissions set for program execution.
Types of Shells
Several types of Shells available are listed below.
- Bourne Shell
- Bash Shell
- C Shell
- TENEX Shell
- Korn Shell
- Z Shell
-
Fish Shell
In this article, we will focus mainly on the Bash Shell. This is because it is the standard shell that is intuitive and flexible. It is the default shell of many Linux distributions today. It is very well-compatible with other shell types and carries many improvements over previous shell types. These improvements include Command-line editing, Job Control, Infinite size command history, etc.
Important Commands
- echo
It simply prints the line of text. It is similar to the ‘println’ keyword of Java.
- file
It returns the type of script file.
- type
It displays how the shell command’s arguments will be interpreted. That means whether the commands used will be read-only, write-only, read-write only, or read-write-executable.
- whereis
It tells you the location of the source image, executable file, and manual pages of any shell command.
- which
It is used to specify the file to be used for any shell script. You need to mention a particular file name here.
Starting with Shell Scripting
Pre-preparation
1. To start with Shell Scripting, open the terminal using the desktop icon or the shortcut key ‘Ctrl+Alt+T’.

2. Now, check the shell types your Operating System supports. Use the command ‘cat /etc/shells’ for the same and press enter. You will see a list of shells your operating system supports.


3. In this article, we are using Bash Shell. So, to know the location of this Bash Shell, use the ‘which bash’ command and press enter.

We have completed all the pre-preparation parts.
Creating a Shell File
We will clear the screen for a fresh start. To create a shell file, follow these steps.
1. Navigate to the Desktop folder or directory. Use the command in the image below.
2. Create a new shell script file in that directory, ‘hello.sh’. We will use the ‘touch’ mode for the same. Note that ‘.sh’ extension is not necessary for execution. We have used it here to differentiate a shell file from other files. It is considered a good practice to use this extension. Also, the ‘touch’ mode provides only read and write permissions. Use the command in the image below.

3. Please enter to create the ‘hello.sh’ file finally.
You will see a ‘hello.sh’ file on your desktop.
Creating a Shell Script
Now, we will create our first and very simple shell program. This bash shell program will print ‘Hello World’. Use the following steps for the proper execution. Note that you can use any editor of your choice. Double-click on the shell file to open the default editor. Here, we will use Visual Studio Code as our editor. We will use the ‘code .’ command to open the previously created shell file in Visual Studio Code.

1. Open the editor and see the directory you imported using the above command. You will see an empty shell script.

2. Use the command in the image below for proper execution.

3. Save the command and minimize the editor.
4. Execute the shell script in the terminal. It shows permission denied. It is because of the ‘touch’ mode we used.

5. We will update the script’s permissions by adding ‘chmod’ mode. It will add ‘execute’ permission to the shell file.

6. We will execute the script again. It prints ‘Hello World’.

You have now written your first successful shell script.