Day 4 of #90 Days of DevOps:
Introduction to Linux Shell and Shell Scripting:
Some important terminologies before getting into Shell Scripting :
Kernel
Shell
Terminal
Kernel:
The kernel is the heart of the Linux Operating System. It communicates between the hardware and software and manages the below resources for Linux:
File management
Device management
Memory management
Process management etc.,
Shell:
A shell is an interface for the user to use operating system services. Shell accepts human-readable commands from users and converts them into something that the kernel can understand. It is a command language interpreter that executes commands read from input devices such as keyboards or from files. The shell gets started when the user logs in or starts the terminal.
Shell is classified into two categories:
Command Line Shell: A Command Line Shell is a terminal in Linux and a Command Prompt in Windows OS through which the user has to interact with the program.
Graphical Shell: Graphical Shell provides a GUI through which the user has to interact with the program.
There are several shells available for Linux systems :
BASH (Bourne Again SHell) – It is the most widely used shell in Linux systems. It is used as the default login shell in Linux systems and macOS. It can also be installed on Windows OS.
CSH (C SHell) – The C shell’s syntax and its usage are very similar to the C programming language.
KSH (Korn SHell) – The Korn Shell was also the base for the POSIX Shell standard specifications etc.
Depending upon our requirements we will be selecting the Linux shell.
Terminal:
A terminal is a program that provides the user the interface to access the shell through commands.
Shell Scripting:
Shell scripting is an interaction where the shell will be accepting input commands from the user and executing them. Shell can also accept input commands in a file and execute them in a shell, these are called shell scripts. Shell scripts are usually saved with the .sh extension.
What is #!/bin/bash?
/bin/bash is an executable representing the system shell. This is known as shebang. Shebang is a collection of number signs and exclamation marks, that is (#!) at the beginning of a script. #!/bin/bash at the start of the script to instruct the operating system to use bash as a default shell.
Write a Shell Script that prints something:
#!/bin/bash
echo "Hello, This is a blog on Shell Scripting"
Write a Shell Script to take user input, input from arguments and print the variables:
#!/bin/bash
echo "Enter some text"
read text
echo "$text"