Basic Linux Shell Scripting for DevOps Engineers.

Basic Linux Shell Scripting for DevOps Engineers.

When we are using any major operating system, we are indirectly interacting with the?shell. While running Ubuntu, Linux Mint, or any other Linux distribution, we are interacting with the shell by using the terminal.?

Before that one of the basic things, you should know is the architecture of LINUX.

The diagram illustrates the structure of the Linux system, according to the layers concept.

The main components of Linux operating system are?-Application, Shell, Kernel, Hardware, Utilities.

  1. Kernel:?is one of the fundamental parts of an operating system. It makes sure that each of the major procedures of Linux is coordinated with hardware directly. It visualizes the common hardware resources and provide each process with necessary virtual resources. It makes the process to wait in the ready queue and execute in consequently to avoid any kind of conflict. In simple words we can say that it is the core of computer’s operating system which takes complete control over everything in the system.

2. Shell: A shell is special user program which provide an interface to user to use operating system services. Shell accepts 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.

3. Hardware Layer: Hardware layer of Linux is the lowest level of operating system track. It is plays a vital role in managing all the hardware components. It includes device drivers, kernel functions, memory management, CPU control, and I/O operations.

4.?System utility: System utilities are the commend line tools that preforms various tasks provided by user to make system management and administration better. These utilities enable user to perform different tasks, such as file management, system monitoring, network configuration, user management etc.

What is #!/bin/bash? Can we write #!/bin/sh as well?

The line #!/bin/bash is known as a shebang (or hashbang). It is used at the beginning of a script to specify the interpreter that should be used to execute the script. In this case, #!/bin/bash indicates that the script should be run using the Bash shell, which is located at /bin/bash.

Yes, you can write #!/bin/sh as well. This shebang line indicates that the script should be run using the sh shell, which is typically a link to a POSIX-compliant shell. The exact shell that /bin/sh points to can vary between systems; on many systems, it points to a lightweight shell like dash (Debian Almquist Shell) for performance reasons, but it could also be a link to bash or another shell.

Here's a brief comparison of the two:

  • #!/bin/bash: Specifically invokes the Bash shell. Bash includes a variety of extensions and features beyond those found in the POSIX standard, making it a powerful and flexible shell for scripting.
  • #!/bin/sh: Invokes the default system shell, which is expected to be POSIX-compliant. This ensures better portability across different Unix-like systems since scripts written for sh are more likely to run without modification on various platforms.

Using #!/bin/sh is recommended if you want your script to be portable and compatible with different Unix-like operating systems, while #!/bin/bash is preferred if you need specific features provided by Bash.

What is Linux Shell Scripting?

Linux shell scripting involves writing programs (scripts) that can be run by a Linux shell, such as bash (Bourne Again Shell). These scripts automate tasks, perform system administration tasks, and facilitate the interaction between users and the operating system.

?Let do some hand-ons in LINUX based on this topic:- So here are the tasks we will be doing today:-

  • Write a Shell Script which prints I will complete #90DaysOofDevOps challenge
  • Write a Shell Script to take user input, input from arguments and print the variables.
  • Write an Example of If else in Shell Scripting by comparing 2 numbers.

  1. Write a Shell Script which prints I will complete #90DaysOofDevOps challenge.

For this we will create one empty file with .sh extension and using vim editor we will use echo command to print 'I will complete #90DaysOofDevOps'. We will give all the permission for execution by using chmod command - chmod 775 file name. Then we will execute it by using ./filename. Refer the picture down to see all the commands in series which i used to print the message.

2. Write a Shell Script to take user input, input from arguments and print the variables. OR Write an Example of If else in Shell Scripting by comparing 2 numbers.

This script will accept the two command line input from user and tell which number is greater.

?Conclusion:-Shell scripting is an essential skill for any DevOps professional. It enables us to automate tasks, manage systems efficiently, and handle complex workflows with ease. By mastering the basics of shell scripting, we're laying a strong foundation for our DevOps journey. Keep practicing and experimenting with different scripts to enhance your skills. Stay tuned for more exciting lessons

要查看或添加评论,请登录

Riya Negi的更多文章

  • Kubernetes Overview

    Kubernetes Overview

    What is Kubernetes and Why Do We Call It K8s? Kubernetes (often abbreviated as K8s) is an open-source platform for…

    1 条评论
  • Jenkins Important Interview Questions

    Jenkins Important Interview Questions

    Important Interview Questions. Jenkins is a cornerstone of modern CI/CD pipelines, and mastering it can give you a…

  • Mastering Jenkins Agents!

    Mastering Jenkins Agents!

    The Jenkins Master, often referred to as the Jenkins Server, is the core component in a Jenkins architecture. It…

  • Jenkins Declarative Pipeline with Docker

    Jenkins Declarative Pipeline with Docker

    Hello Connections, So we will start with Jenkin Declarative pipeline with Docker. Before that we should know why to…

    2 条评论
  • Jenkins Declarative Pipeline

    Jenkins Declarative Pipeline

    So, Lets go deep into Jenkins and learn to start Pipeline in Jenkins. First let basics of Pipeline and all stuffs.

  • Complete Jenkins CI/CD Project

    Complete Jenkins CI/CD Project

    Let Set Up the Jenkins CI/CD Project For this follow these step carefully and here we begins Step 1: Fork the…

  • Jenkins Freestyle Project for DevOps Engineers.

    Jenkins Freestyle Project for DevOps Engineers.

    What is CI/CD? CI/CD stands for Continuous Integration (CI) and Continuous Deployment (CD) (or Continuous Delivery). It…

  • Getting Started with Jenkins

    Getting Started with Jenkins

    What is Jenkins? Jenkins is an open-source continuous integration (CI) and continuous delivery/deployment (CD)…

  • Docker Important interview Questions.

    Docker Important interview Questions.

    1. What is the difference between an Image, Container, and Engine? Image: An image is a lightweight, stand-alone…

  • Docker Cheat Sheet

    Docker Cheat Sheet

    Docker is a powerful tool for containerization that enables developers to package applications along with their…

社区洞察

其他会员也浏览了