Day4: Basic Linux Shell Scripting

·

3 min read

What is Kernel

Kernel is central component of an operating system that manages operations of computer and hardware. It basically manages operations of memory and CPU time. It is core component of an operating system. Kernel acts as a bridge between applications and data processing performed at hardware level using inter-process communication and system calls.

Kernel loads first into memory when an operating system is loaded and remains into memory until operating system is shut down again. It is responsible for various tasks such as disk management, task management, and memory management.

What is Shell

A shell is special user program which provide an interface to user to use operating system services. Shell accept human readable commands from user and convert them into something which kernel can understand. It is a command language interpreter that execute commands read from input devices such as keyboards or from files. The shell gets started when the user logs in or start the terminal.

What is Linux Shell Scripting?

A shell script is a computer program designed to be run by a linux shell, a command-line interpreter. The various dialects of shell scripts are considered to be scripting languages. Typical operations performed by shell scripts include file manipulation, program execution, and printing text.

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

#!/bin/bash is called a "shebang" or "hashbang". It is a special instruction that tells the Unix/Linux shell which interpreter to use to execute the script. In this case, #!/bin/bash indicates that the script should be run using the Bash shell.

Yes, you can also use #!/bin/sh in your script. However, this would instruct the shell to use the default shell interpreter, which may be different from Bash. sh is the original Unix shell and is generally available on all Unix/Linux systems.

The difference between #!/bin/bash and #!/bin/sh is that bash is an enhanced version of sh with additional features and functionality, such as better support for scripting, enhanced history, and more advanced command-line editing capabilities. However, sh is a more lightweight shell and may be more suitable for simple scripts that do not require advanced features.

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

This can be printed by simple echo commmand as follows:

Now print this using sh <file.sh> command as below

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

The script is as below

#!/bin/bash

echo "Enter your name"

read username

echo "Hello $username"

The result is:

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

Sytax:

#!/bin/bash

echo "enter the first number"

read num1

echo "enter the second number"

read num2

if [ $num1 -gt $num2 ]; then

echo "$num1 is greater than $num2"

elif [ $num1 -lt $num2 ]; then

echo "$num1 is less than $num2"

else echo "$num1 is equal to $num2"

fi

the result is as follows: