Day 4: Linux commands with Shell Scripting

What is Kernel ?

Kernel is kernel is the core part(heart) of an operating system, written in C language. Kernel is also called "LINUX", itself. The kernel helps the operating system interact with hardware and perform operations that come from the shell, which are executed in the form of shell commands. . It also handles important tasks like file management, security, and allowing different programs to run at the same time.

What is Shell?

Shell is a program that acts as a bridge between the user and the operating system. It allows you to interact with the system by typing commands. Shell acts as interpreter between shell commands, shell translate commands into machine level language and give to kernel to perform operations.

What is Shell Scripting?

In shell scripting, we write group of commands in .sh file to perform the task without any human intervention, helps to automate the task and mostly used for repetitive task example: file backups, system monitoring, or batch file processing.

We got different shell languages : bash, zsh, fish , and more.

They are written in a shell language, such as Bash, and are executed by the shell, allowing users to streamline their workflows and save time on routine tasks.

What exactly is shebang ?

Shebang (#!) is a special character sequence at the very beginning of a script file that tells the operating system which interpreter to use to run the script.

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

#! is called a shebang (or hashbang), #!/bin/bash and #!/bin/sh specify which shell we are using, basically "BASH" is more advance version of "SH". If you want more portable version of scripting with oldskool commands we use "sh" and if we want to use modern day (advance) commands in shell we use "bash".

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

$vim devops_challenge.sh

#!/bin/bash#

echo "I will complete #90DaysOfDevOps challenge."

Now, to run this script: $ chmod +x devops_challenge.sh or chmod 755 devops_challenge.sh

$./devops_challenge.sh

Write a Shell Script that takes user input, input from arguments, and prints the variables.

$./input_script.sh one

#!/bin/bash#

echo"Please enter your name:"

read name

echo "Hello, $name! and argument is $1".

Provide an example of an If-Else statement in Shell Scripting by comparing two numbers.

#!/bin/bash

Take user input

echo "Please enter your name:" read name

Input from arguments

if [ $# -gt 0 ]; then echo "Your first argument is: $1" else echo "No arguments provided." fi

Print the variables

echo "Hello, $name!"