Shell Scripting — Create your first shell script

An open-source computer software called shell scripting was created to be executed by the Unix/Linux shell. A tool called shell scripting allows you to create a list of instructions that the shell will carry out. It can consolidate long and repetitive command sequences into a single, straightforward script that can be stored and executed whenever, which saves time and effort on programming.
Describe Shell.
UNIX refers to the interface between a user and an operating system service as a “shell.” Shell offers users a user interface, receives human-readable inputs into the system, executes those commands that can run automatically, and outputs the results of the programme as a shell script.
There are various parts that make up an operating, but its two main parts are:
- Kernel
- Shell
How to Write Shell Script in Linux/Unix
Text editors are used to create Shell Scripts. Open a text editor software on your Linux system, create a new file, and start typing a shell script or shell programme. Then, grant the shell permission to execute your script and save it wherever the shell can access it.
Let’s examine the procedures for writing a shell script:
- Use the vi editor to create a file (or any other editor). Give your script a.sh extension.
- #! /bin/sh will launch the script.
- Develop some code.
- The script should be saved as filename.sh.
- Run the script by typing bash filename.sh.
Make a quick script now:
#!/bin/sh
ls

Command ‘ls’ is executed when we execute the scrip sample.sh file.
Adding shell comments
Commenting is important in any program. In Shell programming, the syntax to add a comment is
#comment
Let us understand this with an example.

Shell Variables: What Are They?
Variables store data in the form of characters and numbers, as was previously mentioned. Similarly to this, only the shell can access shell variables, which are used to store data.
For instance, the code that follows creates a shell variable and prints it
variable ="Hello"
echo $variable
Below is a small script which will use a variable.
#!/bin/sh
echo "what is your name?"
read name
echo "How do you do, $name?"
read remark
echo "I am $remark too!"

As you can see, the programme chose the value Joy for the variable “name” and excellent for the variable “remark.”
This script is easy to read. Advanced scripts with conditional statements, loops, and functions are possible to create. Shell scripting will simplify your life and make managing Linux systems simple.
Summary:
- Kernel is the nucleus of the operating systems, and it communicates between hardware and software
- Shell is a program that interprets user commands through CLI like Terminal
- The Bourne shell and the C shell are the most used shells in Linux
- Linux Shell scripting is writing a series of commands for the shell to execute
- Shell variables store the value of a string or a number for the shell to read
- Shell scripting in Linux can help you create complex programs containing conditional statements, loops, and functions
- Basic Shell Scripting Commands in Linux: cat, more, less, head, tail, mkdir, cp, mv, rm, touch, grep, sort, wc, cut and, more.