Basic Linux Shell Scripting for DevOps Engineers.
#90 Days of DevOps Challenge - Day 4
Table of contents
- What is Linux Shell Scripting?
- Explain in your own words and examples, what is Shell Scripting for DevOps.
- What is #!/bin/bash? can we write #!/bin/sh as well?
- Write a Shell Script which prints I will complete #90DaysOofDevOps challenge :-
- Write a Shell Script to take user input, input from arguments and print the variables.
- Write an Example of If else in Shell Scripting by comparing 2 numbers
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.
Explain in your own words and examples, what is Shell Scripting for DevOps.
A shell script is a text file that contains a sequence of commands for a UNIX- based operating system. It is called a shell script because it combines a sequence of commands, that would otherwise have to be typed into the keyboard one at a time, into a single script.
What is
#!/bin/bash?
can we write#!/bin/sh
as well?
#! is called a SHEBANG.This represents which interpreter a script should be interpreted with .
#!/bin/bash This is a header command which represents it is a bash/shell script #!/bin/bash is this is not provided it often considers #!/bin/ sh which would be same in most cases. When you put #!/bin/bash in your script, even if you run the script in a different shell, the kernel will know which shell to interpret it with
Yes, we can use #!/bin/sh in our shell script should be executed by the default shell on the system.
Write a Shell Script which prints
I will complete #90DaysOofDevOps challenge
:-
#!/bin/bash
echo "I will complete #90DaysOofDevOps challenge"
Output :-
Write a Shell Script to take user input, input from arguments and print the variables.
#!/bin/bash
echo "Please Enter Your Name"
read name
echo "Please Enter Your Age"
read age
echo "Please Enter your Address"
read addr
echo "$name is a $age year and $name is from $addr"
Output:-
Write an Example of If else in Shell Scripting by comparing 2 numbers
#!/bin/bash
echo "Please Enter FirstNumber"
read num1
echo "Please Enter SecondNumber"
read num2
if [ $num1 -gt $num2 ]
then
echo "$num1 is greater than $num2"
else
echo "$num2 is greater than $num1"
fi
Output:-
Thank you for reading!! I hope you find this article helpful!!
if any query or if any correction to be done in this blog please let me know.
Happy Learning!!
Saikat Mukherjee