Basic Linux Shell Scripting for DevOps Engineers.

#90 Days of DevOps Challenge - Day 4

Basic Linux Shell Scripting for DevOps Engineers.

A shell script is a computer program designed to be run by the Unix shell, a command-line interpreter. It is a set of commands and instructions written as text files that can be executed by the shell interpreter. Essentially, shell scripts are scripts designed to automate tasks that would normally be executed manually on a command prompt.

Shell scripts can be used to automate a wide range of activities, including system administration, configuring applications, processing text and data files, and more. Some common tasks include system maintenance, backups, file manipulation, and web server processes.

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

    Shell scripting is a programming language that is used to automate tasks on a Unix-like operating system. It is a powerful tool that can be used to perform a variety of tasks, such as:

    • Automating repetitive tasks

    • Executing commands on remote servers

    • Creating and managing files and directories

    • Processing data

    • Creating scripts to perform complex tasks

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

    The line #!/bin/bash is called a shebang line. It tells the operating system which interpreter to use to run the script. In this case, the interpreter is bash, which is a Bourne-again shell.

    You can also write #!/bin/sh, which will tell the operating system to use the Bourne shell to run the script. The Bourne shell is a more basic shell than the bash, so it may not support all of the features of the bash.

    It is generally recommended to use #!/bin/bash if you are writing a new script. This will ensure that your script can take advantage of all of the features of bash.

  • Write a Shell Script that prints I will complete the #90DaysOofDevOps challenge.

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

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

      #!/bin/bash
      echo "what is your name type here : "
      read name 
      echo "what is your age :"
      read age
      echo "my name is $name and i am $age years old ."
    

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

      #!/bin/bash
    
      echo "Provide the first number :- "
      read num1
      echo "Provide the second number : "
      read num2
      if [ $num1  -gt  $num2 ]
      then
      echo  "The number $num1 is greater than $num2 ."
      else
      echo  "The number $num2 is greater than $num1 . "
      fi
    

Devops#devops,#90daysofDevOps

Thank you for reading!! I hope you find this article helpful!!

if any query or if any correction to be done in this blog please let me know.

Happy Learning!!