Hi Everyone, welcome back today we are going to simplify one piece puzzle: Linux Shell Scripting. In this beginner-friendly guide, we'll break it down into digestible bits and see how it fits into the larger DevOps picture.
What is Kernel
The kernel is a computer program that is the core of a computer’s operating system, with complete control over everything in the system.
What is Shell
A shell is a special user program that provide an interface to the 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.
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. It's a user program that serves as an interface between you and the operating system. You might wonder how you communicate with your computer – that's where the shell comes in. It takes the commands you type and makes them understandable to the kernel. It's like a translator for your computer.
#!/bin/bash vs. #!/bin/sh
The #!/bin/bash
is called a shebang or hashbang. It tells the system which interpreter to use for the script. You can also use #!/bin/sh
, but it might use a different interpreter. bash
is more common and provides additional features.
Steps to Create a Shell Script :
Step 1: Use any editor vim or nano script
Syntax: vim first_
script.sh
Step 2: Permit to execute the file
Syntax: chmod <<permission>> <<
filename.sh
\>>
chmod 755 first_
script.sh
This will set the permission read, write, execute (7), for group and others permission is being read and execute (5)
Shell Script Example
#!/bin/bash
echo "I will complete #90DaysOfDevOps challenge"
The above script will print the message "I will complete #90DaysOfDevOps challenge"
when executed.
- Write a Shell Script to take user input, input from arguments and print the variables.
#!/bin/bash
echo "Enter your name : "
read Name
echo "Your name is : $Name"
Write an Example of If else in Shell Scripting by comparing 2 numbers
#!/bin/bash a=4 b=5 if [ $a -gt $b ]; then echo "$a is Greater than $b" else echo "$b is greater than $a" fi
This script compares two numbers,
a
andb
, and tells you which one is greater.Shell scripting is a powerful tool for automating tasks and making our DevOps journey smoother. With the right scripts, you can achieve more in less time. So, embrace the shell, start scripting, and make your computer work for you!