Skip to main content

Command Palette

Search for a command to run...

Task Basic Linux Shell Scripting for DevOps Engineers (Day 4)

Published
3 min read
Task Basic Linux Shell Scripting for DevOps Engineers (Day 4)
J

I am continue learning variety of DevOps technologies, including AWS, Linux, Python, Shell Scripting, Docker, Terraform, Jenkins, Git/GitHub, and Computer Networking. I have a strong ability to troubleshoot and resolve issues, and are consistently motivated to expand the knowledge and skills through exploration of new technologies.

#90 days of DevOps challenge- Day4

Tasks

  • Explain in your own words and examples, what is Shell Scripting for DevOps.

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

  • 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) What is Kernel

In computer science, Kernel is a computer program that is a core or heart of an operating system. Before discussing kernel in detail, let's first understand its basic, i.e., Operating system in a computer.

Functions of a Kernel

  • Device Management

  • Memory Management

  • Resource Management

  • Accessing Computer Resources

(2) What is Shell

A Shell provides you with an interface to the Unix system. It gathers input from you and executes programs based on that input. When a program finishes executing, it displays that program's output.

Shell is an environment in which we can run our commands, programs, and shell scripts. There are different flavours of a shell, just as there are different flavours of operating systems. Each flavour of the shell has its own set of recognized commands and functions.

Shell Types

In Unix, there are two major types of shells −

  • Bourne shell − If you are using a Bourne-type shell, the $ character is the default prompt.

  • C shell − If you are using a C-type shell, the % character is the default prompt.

The Bourne Shell has the following subcategories −

  • Bourne shell (sh)

  • Korn shell (ksh)

  • Bourne Again shell (bash)

  • POSIX shell (sh)

The different C-type shells follow −

  • C shell (csh)

  • TENEX/TOPS C shell (tcsh)

    (3) What is Linux Shell Scripting?

Shell scripting is the process of writing scripts or programs using a shell, which is a command-line interpreter that allows you to execute commands and scripts. It's a scripting language used for automating tasks on a Unix/Linux system, particularly in DevOps, where it can be used for tasks such as deployment, monitoring, and infrastructure management.

The "#!/bin/bash" line at the top of a script tells the system that the script should be interpreted using the bash shell, which is the default shell on most Unix/Linux systems.

To find out where Bash is located in our system, we can use the which command: You can also use other shells such as "#!/bin/sh" for the Bourne shell or "#!/usr/bin/env bash" to locate the bash interpreter on the system.

$ which bash
/usr/bin/bash

Task

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

#!/bin/bash
echo "I will complete #90DaysOfDevOps challenge"

  • Write a Shell Script to take user input, input from arguments and print the variables.

        #!/bin/bash
        echo "Enter your name:"
        read name
        echo "Hello, $name!"
    

    • *Write an Example of If else in Shell Scripting by comparing 2 numbers

    #!/bin/bash
    num1=10
    num2=20
    if [ $num1 -gt $num2 ]
    then
      echo "$num1 is greater than $num2"
    else
      echo "$num2 is greater than $num1"
    fi

Thank you for reading this Blog. Hope you learned something new today! If you found this blog helpful, please like, share, and follow me for more blog posts like this in the future.