Basic Linux Shell Scripting for DevOps Engineers.


What is Kernel
The kernel is a computer program that is the core of a computer’s operating system, with complete control over everything in the system.
What is Shell
A shell is special user program which provide an interface to user to use operating system services. Shell accept human readable commands from user and convert them into something which kernel can understand. It is a command language interpreter that execute commands read from input devices such as keyboards or from files. The shell gets started when the user logs in or start the terminal.
Following are some different types of shells used on Linux.
Bourne shell (sh)
Bourne-Again shell (bash)
C shell (csh)
Korn shell (ksh)
Z shell (zsh)
Fish shell (fish)
Why use Shell Scripting?
Shell scripting is used for a variety of tasks, including system administration, network management, and application development.
Following are some use cases of shell scripting :
Automation: Shell scripting can be used to automate time-consuming processes like file transfers, backups, and system maintenance.
Customization: Shell scripting allows users to customize and extend the functionality of their command-line interfaces.
Flexibility: Shell scripting helps users to develop complicated programs that execute various tasks.
Portability: Shell scripts are a portable solution for automation and management tasks as they can be executed on any Unix or Linux machine.
Let's write our first bash script !😃
Step 1: Create a
test.sh
file and use thenano
/vi/vim command to edit it. There are also other ways to edit files but I find vim is the easiest. create the file then change the permission.Step2: First we'll write shebang or hashbang,
#!
it is used to tell the kernel which interpreter should be used to run the bash script. This#!/bin/bash
statement tells the kernel to interpret it as a bash script. Then we'll print hello world as follows.Step3: Finally we'll run
bash
test.sh
to run the file you'll able to see"
this is my test file for devops engineer"
in the terminal.Hurray! 🤩 you just wrote your first bash script. Now let's dive deeper into bash scripting.
Variables
Variables are used to store data that can be used in shell scripts. To create a variable, simply assign a value to it using the
=
sign.then output
👋 Conclusion :
In this blog, About code shell scripting , in the next blog we will cover linux Topics.
Thanks for read my blog if you liked it this blog please like and commend.
Contact me on linkedin
check out my GitHub for more resource GitHub
Subscribe to my newsletter
Read articles from Pradeep Chitroliya directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
