DAY-4 #90DayOfDevOps

DAY-4 #90DayOfDevOps

Task given by #TrainWithShubham.

What is a shell?

In short, a shell is a program that acts as a user interface to interact with an operating system. It allows users to execute commands, access system utilities, and manage processes. Shells can provide a command-line interface (text-based) or a graphical user interface (GUI) to interact with the system. They interpret user commands and communicate with the operating system's kernel to execute them.

What is a kernel?

In short, a kernel is the core component of an operating system that manages system resources, facilitates communication between software and hardware, and provides essential services. It controls processes, memory, devices, and file systems, ensuring the proper functioning of the computer system.

Linux Shell Scripting for DevOps

Shell scripting for DevOps refers to the practice of using shell scripts to automate and streamline various tasks and processes involved in DevOps practices. DevOps aims to enhance collaboration between development and operations teams, promoting faster software development, continuous integration, and delivery. Shell scripting plays a crucial role in achieving these goals by automating repetitive tasks, managing infrastructure, deploying applications, and facilitating system configurations.

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

The #!/bin/bash or shebang line is a special comment placed at the beginning of a shell script. It specifies the interpreter that should be used to execute the script. In this case, #!/bin/bash indicates that the script should be interpreted and executed by the Bash shell. Bash is a widely used shell with additional features compared to the standard Bourne shell (#!/bin/sh). While both can be used, Bash is preferred for its expanded functionality and compatibility with a wide range of Linux distributions.

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

Example of a Shell Script that prints "I will complete #90DaysOfDevOps challenge":

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

This script starts with the shebang line #!/bin/bash and uses the echo command to print the desired message.

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

Example of a Shell Script that takes user input, input from arguments, and prints the variables:

#!/bin/bash
echo "Enter your name:"
read name
echo "Your name is: $name"
echo "First argument: $1"
echo "Second argument: $2"
$ ./new_shell.sh zeba rashid

Enter your name:

farhan shamim

Your name is: farhan shamim

First argument: zeba

Second argument: rashid

This script prompts the user to enter their name using the read command. It then prints the name using the variable $name. The script also demonstrates how to access command-line arguments, where $1 represents the first argument passed to the script and $2 represents the second argument.

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

Example of If-Else in Shell Scripting by comparing two numbers:

#!/bin/bash
num1=10
num2=5

if [ $num1 -gt $num2 ]; then
  echo "num1 is greater than num2"
elif [ $num1 -eq $num2 ]; then
  echo "num1 is equal to num2"
else
  echo "num1 is less than num2"
fi

In this script, we compare num1 and num2 using if-else statements. The -gt operator checks if num1 is greater than num2, the -eq operator checks for equality, and the else statement handles the case when num1 is less than num2. The corresponding message is printed based on the comparison result.

Get Connected:

If you have any suggestion about this post feel free to let me know and be updated on my blog in the following ways:

LinkedIn Twitter Github

#TrainWithShubham #DevOps #chatgpt #AI #devops #devopsengineer #devops2023 #devopscommunity #devopslife #devopsnotes #DevOpsGuys #DevOpsHandbook #devopsinuk #shellscript #linux