Basic Linux Shell Scripting for DevOps Engineers: Day-4

Basic Linux Shell Scripting for DevOps Engineers: Day-4

What is Kernel:

The kernel is the core component of the operating system that acts as a bridge between the hardware and software, managing system resources, controlling input/output operations, and providing essential services to applications.

What is Shell:

The shell is the interface between the user and the operating system, providing a command-line environment to execute commands and scripts. The shell interprets user inputs, manages system processes, and enables the automation of tasks through scripting. It is a powerful tool that allows users to interact with the system and perform complex operations efficiently.

Shell Scripting for DevOps:

For DevOps professionals, a shell is an essential tool that enables them to automate tasks, manage server configurations, and deploy applications efficiently. The shell provides a command-line interface that allows developers and operations teams to interact with the system and perform complex operations.

What is #!/bin/bash? can we replace it with #!/bin/sh?

#!/bin/bash is known as a shebang or hashbang, which is a special sequence of characters that specifies the interpreter that should be used to execute a script. In this case, #!/bin/bash specifies that the script should be executed using the Bash shell.

Also, we can use #!/bin/sh as a shebang. However, there is a difference between the two. #!/bin/sh specifies that the script should be executed using the default shell interpreter, which is usually Bash on most Linux systems. However, it can also be another shell, such as Dash or KornShell, depending on the system configuration.

On the other hand, #!/bin/bash specifically specifies the use of the Bash shell, which may be important if your script relies on Bash-specific features or syntax.

Shell Script which prints "I will complete #90DaysOofDevOps challenge":

This is a simple shell script that prints the message "I will complete #90DaysOfDevOps challenge" to the terminal.

"A Shell Script to take user input, input from arguments and print the variables":

This is a simple shell script that takes user input and prints a message to the terminal.

The script prompts the user to enter their name using the echo command and then reads their input using the read command. It then prompts the user to enter the name of the city where they live, reads their input again using the read command, and finally prints a message that includes the city name they entered.

The message that is printed on the terminal will say "ohh!!! {Chandigarh} is a beautiful city", where {city name} is the name of the city that the user entered.

You can save this script with a .sh extension, and execute it by running the command bash script name. sh (assuming the file is saved in the current directory).

Usage of If/else in Shell Scripting by comparing 2 numbers:

This is a simple shell script that uses an if-else statement to compare two numbers and print a message to the terminal.

The script sets the values of num1 and num2 to 2 and 5 respectively. It then uses the if statement to compare the values of num1 and num2 using the -gt operator, which checks if num1 is greater than num2. If num1 is greater than num2, the script will print the message "2 is greater than 5". If num2 is greater than num1, the script will print the message "5 is greater than 2".

You can save this script with a .sh extension

#Thanks for reading my post on shell scripting! I hope you found these tips and tricks helpful. Now it's time to put your new skills to the test. Whether you're a seasoned pro or a beginner, I encourage you to start experimenting with shell scripts and see what you can create.


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

#!/bin/bash
# Take user input
echo "Enter your name: "
read name
echo "where you live"
read input
echo "ohh!!! $input is a beautiful city"

-------------------------------------------------------------------

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

NOTE:

"I'm using Visual Studio Code as my code editor and writing my scripts directly on my AWS instance. This powerful combination makes it easy to create, edit, and manage shell scripts for all kinds of tasks."

Shubham Londhe

DevOps Coder